Giter VIP home page Giter VIP logo

lrucache's Introduction

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.

lrucache's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.