{"id":28600740,"url":"https://github.com/solkin/disk-lru-cache","last_synced_at":"2026-01-19T02:06:06.670Z","repository":{"id":54713919,"uuid":"146182984","full_name":"solkin/disk-lru-cache","owner":"solkin","description":"💾 Disk LRU cache with persisted journal","archived":false,"fork":false,"pushed_at":"2025-02-23T11:33:24.000Z","size":444,"stargazers_count":26,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-27T12:46:42.569Z","etag":null,"topics":["android-lib","android-library","cache","disk-cache","disk-lru","disk-lru-cache","disklrucache","file-cache","journal","lru","lru-cache"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/solkin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-26T13:29:04.000Z","updated_at":"2025-04-09T04:27:11.000Z","dependencies_parsed_at":"2023-12-30T02:52:23.596Z","dependency_job_id":"58ced82a-939e-4b87-91b4-3cc0e5b95428","html_url":"https://github.com/solkin/disk-lru-cache","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solkin%2Fdisk-lru-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solkin%2Fdisk-lru-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solkin%2Fdisk-lru-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solkin%2Fdisk-lru-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solkin","download_url":"https://codeload.github.com/solkin/disk-lru-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solkin%2Fdisk-lru-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259280891,"owners_count":22833473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-lib","android-library","cache","disk-cache","disk-lru","disk-lru-cache","disklrucache","file-cache","journal","lru","lru-cache"],"created_at":"2025-06-11T14:38:51.266Z","updated_at":"2026-01-19T02:06:06.657Z","avatar_url":"https://github.com/solkin.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Disk LRU Cache [![](https://jitpack.io/v/solkin/disk-lru-cache.svg)](https://jitpack.io/#solkin/disk-lru-cache) [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-Disk%20LRU%20Cache-green.svg?style=flat )]( https://android-arsenal.com/details/1/7454 )\n\nDisk LRU (least recently used) cache with persisted journal. \nThis cache has specific capacity and location.\nRarely requested files are evicted by actively used.\n\nLightweight and extremely easy to use.\n\n![Cache icon](/cache_icon.png)\n\n### Add dependency\n**Step 1.** Add the JitPack repository to your build file\n```groovy\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n```\n**Step 2.** Add the dependency\n```groovy\nimplementation 'com.github.solkin:disk-lru-cache:\u003cversion\u003e'\n```\nReplace `\u003cversion\u003e` with the latest version from the JitPack badge above.\n\n### Create DiskLruCache\n```java\nlong CACHE_SIZE = 500 * 1024; // Size in bytes\nDiskLruCache cache = DiskLruCache.create(getCacheDir(), CACHE_SIZE);\n```\n\n### Add file into cache\nTo manage some files by cache you just need to invoke `put` method like any `Map`.\n\nKey - any string to request this file from cache.\n\nFile - file, that will be moved into cache.\n\n```java\nString key = \"some-key\";\nFile file = File.createTempFile(\"random\", \".dat\");\ncache.put(key, file);\n```\n\n### Getting file from cache\nTo get file from cache, just invoke `get` method. Yes, also like any `Map`.\n\nKey is the same you put this file into cache\n\nThis method will return `File` you put into cache or `null`, if file was evicted from cache.\n\n```java\nString key = \"some-key\";\nFile file = cache.get(key);\n```\n\n### Delete file from cache\nTo delete file from cache, just invoke `delete` method.\n\nKey is the same you put this file into cache.\n\nFile will be deleted from cache and from journal.\n\nThrows `RecordNotFoundException` if the key is not found in cache.\n\n```java\nString key = \"some-key\";\ntry {\n    cache.delete(key);\n} catch (RecordNotFoundException e) {\n    // Key not found in cache\n}\n```\n\n### Clear cache\nSometime you may need to clear whole cache and drop all stored files.\n\n```java\ncache.clearCache();\n```\n\n### List keys in cache\nTo get all keys, managed by cache, invoke `keySet()` method.\n\nThis will return `Set\u003cString\u003e`.\n\nList all keys in cache may be useful to check all files, stored in cache. \n\n```java\nSet\u003cString\u003e keys = cache.keySet();\n```\n\n\n### Get cache status information\nThere are some useful cache status information, that you can request.\n\n```java\ncache.getCacheSize(); // Cache size in bytes, that you set up on cache creation.\ncache.getUsedSpace(); // Size of all files, stored in cache.\ncache.getFreeSpace(); // Free size in cache.\ncache.getJournalSize(); // Internal cache journal size in bytes.\n```\n\n### Get records information\nTo get detailed information about cached records including LRU order, use `getRecordsInfo()`.\n\nThis returns a list of `RecordInfo` objects sorted by last access time (most recently accessed first).\nRecords at the end of the list will be evicted first when cache overflows.\n\n```java\nList\u003cRecordInfo\u003e records = cache.getRecordsInfo();\nfor (RecordInfo info : records) {\n    String key = info.getKey();           // Key used to store the file\n    String fileName = info.getFileName(); // Actual file name in cache\n    long size = info.getSize();           // File size in bytes\n    long lastAccessed = info.getLastAccessed(); // Timestamp of last access\n}\n```\n\nTo get information about a specific record without updating its access time:\n\n```java\nRecordInfo info = cache.getRecordInfo(\"some-key\");\nif (info != null) {\n    // Record exists\n}\n```\n\n**Note:** `getRecordInfo()` and `getRecordsInfo()` do not update the access time, \nso they can be used for monitoring without affecting LRU order.\n\n### Thread safety\nDiskLruCache is thread-safe. All public methods are synchronized and can be safely called from multiple threads.\n\n### Limitations\n- File size cannot exceed cache size. Attempting to put a larger file will throw `IOException`.\n- Key cannot be `null` or empty. Invalid keys will throw `IllegalArgumentException`.\n\n### Requirements\n- Min SDK: 16 (Android 4.1)\n- Target SDK: 34\n\n### Custom FileManager and Logger\nYou can provide custom implementations of `FileManager` and `Logger`:\n\n```java\nFileManager fileManager = new MyCustomFileManager();\nLogger logger = new MyCustomLogger();\nDiskLruCache cache = DiskLruCache.create(fileManager, logger, CACHE_SIZE);\n```\n\n### License\n    MIT License\n    \n    Copyright (c) 2022-2026 Igor Solkin\n    \n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n    \n    The above copyright notice and this permission notice shall be included in all\n    copies or substantial portions of the Software.\n    \n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n    SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolkin%2Fdisk-lru-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolkin%2Fdisk-lru-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolkin%2Fdisk-lru-cache/lists"}