All Projects → solkin → disk-lru-cache

solkin / disk-lru-cache

Licence: MIT License
💾 Disk LRU cache with persisted journal

Projects that are alternatives of or similar to disk-lru-cache

Olric
Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
Stars: ✭ 2,067 (+9742.86%)
Mutual labels:  cache, lru, lru-cache
cache
LRU-based cache package for Go.
Stars: ✭ 25 (+19.05%)
Mutual labels:  cache, lru, lru-cache
Cache
📦 Nothing but Cache.
Stars: ✭ 2,491 (+11761.9%)
Mutual labels:  cache, disk-cache
hybrid-disk-cache
A hybrid disk cache library that utilized both the solid SQLite3 and file system.
Stars: ✭ 19 (-9.52%)
Mutual labels:  file-cache, disk-cache
memo-async-lru
Memoize Node.js style callback-last functions, using an in-memory LRU store
Stars: ✭ 17 (-19.05%)
Mutual labels:  lru, lru-cache
go-cache-benchmark
Cache benchmark for Golang
Stars: ✭ 47 (+123.81%)
Mutual labels:  lru, lru-cache
LruClockCache
A low-latency LRU approximation cache in C++ using CLOCK second-chance algorithm. Multi level cache too. Up to 2.5 billion lookups per second.
Stars: ✭ 35 (+66.67%)
Mutual labels:  lru, lru-cache
Gcache
An in-memory cache library for golang. It supports multiple eviction policies: LRU, LFU, ARC
Stars: ✭ 1,787 (+8409.52%)
Mutual labels:  cache, lru
hyperlru
Tiny & Fast LRU Implementation as possible.
Stars: ✭ 34 (+61.9%)
Mutual labels:  lru, lru-cache
lru
LRU cache using go generics
Stars: ✭ 108 (+414.29%)
Mutual labels:  lru, lru-cache
gocache
High performance and lightweight in-memory cache library with LRU and FIFO support as well as memory-usage-based-eviction
Stars: ✭ 15 (-28.57%)
Mutual labels:  lru, lru-cache
elara
Elara DB is an easy to use, lightweight key-value database that can also be used as a fast in-memory cache. Manipulate data structures in-memory, encrypt database files and export data. 🎯
Stars: ✭ 93 (+342.86%)
Mutual labels:  cache, lru-cache
golib
Open version of common golang libraries useful to many projects.
Stars: ✭ 47 (+123.81%)
Mutual labels:  lru, lru-cache
gotcha
[Not Safe For Production] gotcha: inmemory-cache in Go (Golang) with customizable algorithm
Stars: ✭ 13 (-38.1%)
Mutual labels:  cache, lru-cache
wassup
Personal assistant to help you save your personal memories and emotions together, securely
Stars: ✭ 58 (+176.19%)
Mutual labels:  journal
moka
A high performance concurrent caching library for Rust
Stars: ✭ 346 (+1547.62%)
Mutual labels:  cache
cache-trace
A collection of Twitter's anonymized production cache traces.
Stars: ✭ 89 (+323.81%)
Mutual labels:  cache
bk flutter image
flutter image,降低内存使用
Stars: ✭ 32 (+52.38%)
Mutual labels:  cache
codeigniter-cache-helper
📤 A CodeIgniter output cache helper.
Stars: ✭ 19 (-9.52%)
Mutual labels:  cache
storage
Go package for abstracting local, in-memory, and remote (Google Cloud Storage/S3) filesystems
Stars: ✭ 49 (+133.33%)
Mutual labels:  cache

Disk LRU Cache Build Status Codacy Badge Android Arsenal

Disk LRU (least recently used) cache with persisted journal. This cache has specific capacity and location. Rarely requested files are evicted by actively used.

Lightweight and extremely easy to use.

Cache icon

Add dependency

Step 1. Add the JitPack repository to your build file

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

implementation 'com.github.solkin:disk-lru-cache:1.4'

Create DiskLruCache

long CACHE_SIZE = 500 * 1024; // Size in bytes
DiskLruCache cache = DiskLruCache.create(getCacheDir(), CACHE_SIZE);

Add file into cache

To manage some files by cache you just need to invoke put method like any Map.

Key - any string to request this file from cache.

File - file, that will be moved into cache.

String key = "some-key";
File file = File.createTempFile("random", ".dat");
cache.put(key, file);

Getting file from cache

To get file from cache, just invoke get method. Yes, also like any Map.

Key is the same you put this file into cache

This method will return File you put into cache or null, if file was evicted from cache.

String key = "some-key";
File file = cache.get(key);

Delete file from cache

To delete file from cache, just invoke delete method.

Key is the same you put this file into cache

File will be deleted from cache and from journal.

String key = "some-key";
cache.delete(key);

Clear cache

Sometime you may need to clear whole cache and drop all stored files.

cache().clearCache();

List keys in cache

To get all keys, managed by cache, invoke keySet() method.

This will return Set<String>.

List all keys in cache may be useful to check all files, stored in cache.

Set<String> keys = cache.keySet();

Get cache status information

There are some useful cache status information, that you can request.

cache.getCacheSize(); // Cache size in bytes, that you set up on cache creation.
cache.getUsedSpace(); // Size of all files, stored in cache.
cache.getFreeSpace(); // Free size in cache.
cache.getJournalSize(); // Internal cache journal size in bytes.

License

MIT License

Copyright (c) 2021 Igor Solkin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].