Skip to content
This repository has been archived by the owner. It is now read-only.
/ LruCache Public archive

A tiny memory cache implementation which uses a LRU policy.

License

Notifications You must be signed in to change notification settings

hotchemi/LruCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LruCache

Build Status

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 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's API is definitely simple.

Cache<String, String> 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 is the class that specialized in caching Bitmap.

private static final Bitmap A = Bitmap.createBitmap(1, 1, ALPHA_8);

Cache cache = new BitmapLruCache();
cache.put("a", A);

Test

mvn clean test

Support

Java 1.7 or greater.

About

A tiny memory cache implementation which uses a LRU policy.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages