whatisgithub

What is disklrucache?

jakewharton/disklrucache — explained in plain English

Analysis updated 2026-06-26

5,790JavaAudience · vibe coderComplexity · 2/5LicenseSetup · easy

In one sentence

A Java library that saves data to disk and automatically evicts the oldest entries when a size limit is reached, so Android apps avoid re-downloading or re-computing expensive data on every launch.

Mindmap

mindmap
  root((repo))
    Storage
      String key lookup
      Raw byte values
      Filesystem backed
    Eviction
      LRU policy
      Background cleanup
      Size limit enforced
    Safety
      Atomic writes
      Read snapshots
      Graceful error handling
    Integration
      Maven support
      Gradle support
      Android compatible
    Use Cases
      Cache images
      Cache JSON responses
      Avoid re-downloads
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Cache downloaded images in an Android app so they load instantly on the next open without hitting the network again.

USE CASE 2

Store API responses like JSON to disk so your app works offline or starts faster after the first run.

USE CASE 3

Save computed results that are expensive to recalculate, reading from disk instead of reprocessing every time.

What is it built with?

JavaAndroidMavenGradle

How does it compare?

jakewharton/disklrucacheddd-by-examples/librarynightonke/boommenu
Stars5,7905,7865,786
LanguageJavaJavaJava
Setup difficultyeasymoderateeasy
Complexity2/54/52/5
Audiencevibe coderdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

Add the Maven or Gradle dependency, call DiskLruCache.open() with a directory and size limit, then use put/get with string keys.

Apache 2.0, free to use, modify, and distribute in personal or commercial projects. Just keep the license notice.

So what is it?

DiskLruCache is a Java library that saves data to the device filesystem and keeps the total size of that data within a limit you set. When stored data exceeds the limit, the library automatically removes old entries in the background until it fits again. The entries it removes are the ones that have not been accessed recently, which is the meaning of LRU (least recently used). This kind of cache is useful in Android apps when you want to avoid re-downloading or re-computing expensive data on every launch. Instead, you store the result the first time, and on the next run you read it from disk rather than fetching it again. The README notes that the implementation specifically targets Android compatibility. Each item in the cache is identified by a string key. You store values as raw byte sequences, which means you can cache anything from downloaded images to JSON responses to computed results. Reading a cache entry gives you a snapshot of the data at the moment you requested it, any updates happening at the same time do not affect your read. Writing is atomic too: if you commit a change, readers will see either the old data or the new data, never a partially written mix. The library handles some types of filesystem errors gracefully. If a cached file goes missing, the library drops that entry and moves on. Write errors fail without crashing your application. The library is available through Maven and Gradle for standard Java and Android projects. It is authored by Jake Wharton and based on an original implementation from the Android Open Source Project. It is released under the Apache 2.0 license.

Copy-paste prompts

Prompt 1
How do I set up DiskLruCache in my Android project using Gradle and open a cache with a 50 MB size limit?
Prompt 2
Show me how to write a downloaded image to the cache and read it back on the next app launch.
Prompt 3
What happens if a cached file is deleted from the filesystem while my app is running, does DiskLruCache crash or recover?
Prompt 4
How do I store a JSON string in DiskLruCache and retrieve it safely without reading a partially written value?
Prompt 5
How does the LRU eviction work, which entries get deleted first when the cache is full?

Frequently asked questions

What is disklrucache?

A Java library that saves data to disk and automatically evicts the oldest entries when a size limit is reached, so Android apps avoid re-downloading or re-computing expensive data on every launch.

What language is disklrucache written in?

Mainly Java. The stack also includes Java, Android, Maven.

What license does disklrucache use?

Apache 2.0, free to use, modify, and distribute in personal or commercial projects. Just keep the license notice.

How hard is disklrucache to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is disklrucache for?

Mainly vibe coder.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.