use of org.gradle.cache.internal.btree.BTreePersistentIndexedCache in project gradle by gradle.
the class DefaultCacheAccess method newCache.
@Override
public <K, V> MultiProcessSafePersistentIndexedCache<K, V> newCache(final PersistentIndexedCacheParameters<K, V> parameters) {
lock.lock();
IndexedCacheEntry entry = caches.get(parameters.getCacheName());
try {
if (entry == null) {
final File cacheFile = new File(baseDir, parameters.getCacheName() + ".bin");
LOG.info("Creating new cache for {}, path {}, access {}", parameters.getCacheName(), cacheFile, this);
Factory<BTreePersistentIndexedCache<K, V>> indexedCacheFactory = new Factory<BTreePersistentIndexedCache<K, V>>() {
public BTreePersistentIndexedCache<K, V> create() {
return doCreateCache(cacheFile, parameters.getKeySerializer(), parameters.getValueSerializer());
}
};
MultiProcessSafePersistentIndexedCache<K, V> indexedCache = new DefaultMultiProcessSafePersistentIndexedCache<K, V>(indexedCacheFactory, fileAccess);
CacheDecorator decorator = parameters.getCacheDecorator();
if (decorator != null) {
indexedCache = decorator.decorate(cacheFile.getAbsolutePath(), parameters.getCacheName(), indexedCache, crossProcessCacheAccess, getCacheAccessWorker());
if (fileLock == null) {
useCache(new Runnable() {
@Override
public void run() {
// Empty initial operation to trigger onStartWork calls
}
});
}
}
entry = new IndexedCacheEntry(parameters, indexedCache);
caches.put(parameters.getCacheName(), entry);
if (fileLock != null) {
indexedCache.afterLockAcquire(stateAtOpen);
}
} else {
entry.assertCompatibleCacheParameters(parameters);
}
} finally {
lock.unlock();
}
return entry.getCache();
}
Aggregations