Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hotchemi/lrucache
A tiny memory cache implementation which uses a LRU policy.
https://github.com/hotchemi/lrucache
Last synced: 2 months ago
JSON representation
A tiny memory cache implementation which uses a LRU policy.
- Host: GitHub
- URL: https://github.com/hotchemi/lrucache
- Owner: hotchemi
- License: apache-2.0
- Created: 2015-01-11T13:08:05.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-03-11T03:36:27.000Z (almost 7 years ago)
- Last Synced: 2024-10-14T12:43:26.085Z (3 months ago)
- Language: Java
- Size: 160 KB
- Stars: 76
- Watchers: 3
- Forks: 30
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LruCache
[![Build Status](https://travis-ci.org/hotchemi/LruCache.svg)](https://travis-ci.org/hotchemi/LruCache)
A tiny, thread safe memory cache implementation which uses a LRU policy.
> This implementation gives priority to simplicity of API.
> If you want to use a rich API, Use the `LruCache` in Android framework.## How to use
### Cache
[`Cache`](https://github.com/hotchemi/LruCache/blob/master/src/main/java/hotchemi/com/github/Cache.java) is a interface.
It provides six methods as bellow.
- `V get(K key)` - Gets an value for the specified key.
- `V put(K key, V value)` - Puts an value in the cache for the specified key.
- `V remove(K key)` - Removes the entry for key.
- `void clear()` - Clears all the entries in the cache.
- `int getMaxMemorySize()` - Returns the max memory size of the cache.
- `int getMemorySize()` - Returns the current memory size of the cache.#### LruCache
[`LruCache`](https://github.com/hotchemi/LruCache/blob/master/src/main/java/hotchemi/com/github/LruCache.java)'s API is definitely simple.
```java
Cache cache = new LruCache<>();
cache.put("a", "A");
```#### Note
- Default cache item capacity is ten. You can change the capacity via constructor.
- Please override the `getValueSize` if you control memory size correctly.### BitmapLruCache
[`BitmapLruCache`](https://github.com/hotchemi/LruCache/blob/master/src/main/java/hotchemi/com/github/BitmapLruCache.java) is the class that specialized in caching `Bitmap`.
```java
private static final Bitmap A = Bitmap.createBitmap(1, 1, ALPHA_8);Cache cache = new BitmapLruCache();
cache.put("a", A);
```## Test
```sh
mvn clean test
```## Support
Java 1.7 or greater.