Search in sources :

Example 1 with MemoryLruCache

use of info.evelio.carbonite.cache.MemoryLruCache in project carbonite by eveliotc.

the class CacheFactoryImp method buildDefault.

@SuppressWarnings("unchecked")
private Cache<String, T> buildDefault(CacheBuilder options) {
    final CacheType cacheType = options.cacheType();
    switch(cacheType) {
        case MEMORY:
            return new MemoryLruCache<String, T>(new MemoryLruCache.Options(LRU_SIZE));
        case STORAGE:
            // TODO yikes a builder or something, plus kryo needs more config
            final Class type = options.type();
            final File dir = buildCacheDir(options.context(), type);
            final Serializer<T> serializer = new KryoSerializer<T>(new Kryo(), type);
            final Options storageOpts = new Options(dir, MINIMAL_CAPACITY, type, serializer);
            return new StorageLruCache<T>(storageOpts);
        default:
            illegalState(true, "Not yet implemented cache type " + cacheType);
            return null;
    }
}
Also used : MemoryLruCache(info.evelio.carbonite.cache.MemoryLruCache) Options(info.evelio.carbonite.cache.StorageLruCache.Options) CacheOptions(info.evelio.carbonite.cache.CacheOptions) StorageLruCache(info.evelio.carbonite.cache.StorageLruCache) File(java.io.File) Kryo(com.esotericsoftware.kryo.Kryo) CacheType(info.evelio.carbonite.cache.CacheType) KryoSerializer(info.evelio.carbonite.serialization.KryoSerializer)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)1 CacheOptions (info.evelio.carbonite.cache.CacheOptions)1 CacheType (info.evelio.carbonite.cache.CacheType)1 MemoryLruCache (info.evelio.carbonite.cache.MemoryLruCache)1 StorageLruCache (info.evelio.carbonite.cache.StorageLruCache)1 Options (info.evelio.carbonite.cache.StorageLruCache.Options)1 KryoSerializer (info.evelio.carbonite.serialization.KryoSerializer)1 File (java.io.File)1