看看LruCacheObjectPersister.java,这是一个基于 Android LRUCache 的内存对象持久化器。我想扩展这个基类以在内存中缓存字符串或位图旁边的任何 pojos 类。我的目标是在内存中执行多种请求并在缓存中获取结果,它看起来像这样:
class Request1 extends SpiceRequest<Book>{}
class Request2 extends SpiceRequest<Category>{}
getSpiceManager().execute(new Request1(), CACHE_KEY, 5 * DurationInMillis.ONE_MINUTE, new RequestListener<Book>(){});
getSpiceManager().execute(new Request2(), CACHE_KEY, 5 * DurationInMillis.ONE_MINUTE, new RequestListener<Category>(){});
我的问题是如何告诉缓存管理器应该在香料服务中支持这些类型,如下所示:
@Override
public CacheManager createCacheManager(Application application) {
CacheManager cacheManager = new CacheManager();
// I want to store any types instead of bitmap
LruCacheBitmapObjectPersister lruCacheBitmapObjectPersister = new LruCacheBitmapObjectPersister(inFileBitmapObjectPersister, 1024*1024);
cacheManager.addPersister(inFileBitmapObjectPersister);
return cacheManager;
}
我怎样才能做到这一点?