use of com.github.benmanes.caffeine.jcache.Expirable in project caffeine by ben-manes.
the class JCacheLoaderAdapter method load.
@Override
public Expirable<V> load(K key) {
try {
boolean statsEnabled = statistics.isEnabled();
long start = statsEnabled ? ticker.read() : 0L;
V value = delegate.load(key);
if (value == null) {
return null;
}
dispatcher.publishCreated(cache, key, value);
if (statsEnabled) {
// Subtracts the load time from the get time
statistics.recordGetTime(start - ticker.read());
}
return new Expirable<>(value, expireTimeMS());
} catch (CacheLoaderException e) {
throw e;
} catch (RuntimeException e) {
throw new CacheLoaderException(e);
}
}
use of com.github.benmanes.caffeine.jcache.Expirable in project caffeine by ben-manes.
the class JCacheLoaderAdapter method loadAll.
@Override
public Map<K, Expirable<V>> loadAll(Iterable<? extends K> keys) {
try {
boolean statsEnabled = statistics.isEnabled();
long start = statsEnabled ? ticker.read() : 0L;
Map<K, Expirable<V>> result = delegate.loadAll(keys).entrySet().stream().filter(entry -> (entry.getKey() != null) && (entry.getValue() != null)).collect(Collectors.toMap(Map.Entry::getKey, entry -> new Expirable<>(entry.getValue(), expireTimeMS())));
for (Map.Entry<K, Expirable<V>> entry : result.entrySet()) {
dispatcher.publishCreated(cache, entry.getKey(), entry.getValue().get());
}
if (statsEnabled) {
// Subtracts the load time from the get time
statistics.recordGetTime(start - ticker.read());
}
return result;
} catch (CacheLoaderException e) {
throw e;
} catch (RuntimeException e) {
throw new CacheLoaderException(e);
}
}
Aggregations