You might want to consider creating a Map extension (using AbstractMap) and overriding related functions. In general, the extension structure should have:
- The hard memory cache uses a regular card. This must be a size cache object. You can use LinkedHashMap and override removeEldesEntry () to check if the size is exceeded.
this.objectMap = Collections.synchronizedMap(new LinkedHashMap() {
@Override
protected boolean removeEldestEntry(LinkedHashMap.Entry eldest) {
if (size() > HARD_CACHE_CAPACITY) {
}
}
});
- If the cache is exceeded, then put it on the disk
- get, : get ( ) . - ( )
@Override
public Bitmap get(Object key) {
if(key != null) {
if(objectMap.containsKey(key)) {
return objectMap.get(key);
}
if(secondaryCache.containsKey(key)) {
return secondaryCache.get(key);
}
String fileName = "Disk-" + key + ".txt";
File f = new File(cacheDir, fileName);
if(f.exists()) {
Bitmap object = readFromReader(f);
if(object != null) {
objectMap.put((String)key, object);
return object;
}
}
}
return null;
}
, put , . , - . , AbstractMap, , 1000 . ,