Import Java.util.hashmap;import java.util.linkedlist;/* * Android Big Data cache strategy based on Java LinkedList * Original source:/http Blog.csdn.net/zhangphil * * Implementation principle: The principle of the model that: in the linkedlist of the head element is the oldest cache data, at the end of LinkedList is the latest cache data. * Maintain a storage stack in a linkedlist (linked list of type C), add elements in order, and add them sequentially. * * Principle implementation of the specific scheme: whenever the cached Get () method is called, the element is immediately updated from its original location in LinkedList to the last position of LinkedList. * For example, originally: 1,2,3,4,5. When get is 2, the order is now: 1,3,4,5,2. * * When the cache space is full, delete the oldest element (at the head) to make room. * For example, the cache space is 5, the original cache has already cached 5 elements: a,b,c,d,e, * When the element f is added again, because the cache space is 5 no more than 6 elements, so delete the head of the element A, the F appended to the tail into: b,c,d,e,f * * Specific use: Similar to Android LRUCache, publicly disclosed two common (generic, means can save bitmap or similar data) method for storage and read use: * public void put (String key, Object obj); *public Object get (String key); * Generic <key,value> storage and reading model. Note: The user should ensure that the key is unique when stored. * */public class Cachebasedonlinkedlist {//capacity default cache capacity private static int capacity = 30;private Linkedlist
Implementation of Android Big data cache strategy based on Java LinkedList