How to use RoboSpice cache types

186 views Asked by At

Note: this is general question of person new to caching mechanisms on Android.

Why RS uses LRU caching in FlickrSpiceService sample?

There is LruCacheBitmapObjectPersister:

@Override
public CacheManager createCacheManager(Application application) throws CacheCreationException {
    CacheManager manager = new CacheManager();
    InFileBitmapObjectPersister filePersister = new InFileBitmapObjectPersister(getApplication());
    LruCacheBitmapObjectPersister memoryPersister = new LruCacheBitmapObjectPersister(filePersister, 1024 * 1024);
    manager.addPersister(memoryPersister);
    return manager;
}

Why don't remove it and just use InFileBitmapObjectPersister like this:

@Override
public CacheManager createCacheManager(Application application) throws CacheCreationException {
    CacheManager manager = new CacheManager();
    InFileBitmapObjectPersister filePersister = new InFileBitmapObjectPersister(getApplication());
    manager.addPersister(filePersister);
    return manager;
}
1

There are 1 answers

0
nekojsi On

Memory cache (the LruCacheBitmapObjectPersister in this case) is much faster than the file system one (InFileBitmapObjectPersister), but at the same time, it is smaller.

Therefore, using smaller (but faster) memory cache as Level 1 and larger (but slower) file system cache as Level 2 offers improved performance for common usage. You can check this broadly related answer for processor cache for more info. Multilevel cache is a recurring theme in Computer Science.