public <K, V> DistributedCache<K, V> newCache() { MutableConfig copyConfig = new MutableConfig(name, loggingEnabled, maxTTISeconds, maxTTLSeconds, orphanEvictionEnabled, orphanEvictionPeriod, targetMaxInMemoryCount, targetMaxTotalCount, capacityEvictionPolicyDataFactory); if (CacheConfigFactory.DSO_ACTIVE) { return new DistributedCacheImpl<K, V>(copyConfig); } else { return new LocalCache<K, V>(copyConfig); } }
public StoreImpl(CacheConfig config) { config = (config instanceof ImmutableConfig) ? config : new ImmutableConfig(config); this.data = new DistributedCacheImpl<String, V>(config); }
/** * This method should always be called instead of System.currentTimeMillis() so that time can be controlled by the * TimeSource. * * @return The current time according to the TimeSource */ private int getTime() { return this.timeSource.now(); }
private static CacheConfig getDefaultConfig() { MutableConfig config = new MutableConfig(); config.setMaxTTISeconds(0); config.setMaxTTLSeconds(0); config.setOrphanEvictionEnabled(false); ImmutableConfig rv = new ImmutableConfig(config); if (rv.isEvictionEnabled()) { throw new AssertionError("Eviction is enabled? " + config); } return rv; }
/** * Construct a new cache configuration. * @return A new configuration with all default values. */ public static CacheConfig newConfig() { return new MutableConfig(); } }
public void evictExpiredLocalElements() { if (isEvictionEnabled()) { Collection<Map.Entry<K, TimestampedValue<V>>> localEntries = data.getAllLocalEntriesSnapshot(); invalidateCacheEntries(new EntrySnapshotIterator(localEntries)); } }
public void evictExpiredLocalElements() { if (isEvictionEnabled()) { invalidateCacheEntries(); } }
public MutableConfig() { refresh(); registerTCLoggerIfActive(); }
public V unlockedGet(final K key) { return getValueSafe(getNonExpiredEntryUnlocked(key, true)); }
public boolean isEvictionEnabled() { return getMaxTTISeconds() > 0 || getMaxTTLSeconds() > 0; }
public boolean unlockedContainsKey(final Object key) { TimestampedValue<V> entry = getNonExpiredEntryUnlocked((K) key, false); return entry != null; }
/** * Terracotta <on-load> method */ public void initializeOnLoad() { // XXX: this can potentially start another evictor if one is already running? initializeOnLoad(true); }
void setTimeSource(TimeSource timeSource) { ((DistributedCacheImpl)data).setTimeSource(timeSource); } }
public boolean isEmpty() { return size() == 0; }
public boolean containsKey(final Object key) { TimestampedValue<V> entry = getNonExpiredEntryCoherent((K) key, false); return entry != null; }
private TimestampedValue<V> getNonExpiredEntryUnsafe(K key, boolean markUsed) { return getNonExpiredEntry(key, markUsed, GetType.UNSAFE); }
/** * Construct a new cache instance based on the configuration changes specified in this instance of the builder so far. * If Terracotta is not being used, a non-clustered implementation will be returned instead. * * @param <K> Key type * @param <V> Value type * @return Map constructed by this method based on previous parameters and defaults */ public <K, V> DistributedCache<K, V> newCache() { MutableConfig copyConfig = new MutableConfig(name, loggingEnabled, maxTTISeconds, maxTTLSeconds, orphanEvictionEnabled, orphanEvictionPeriod, targetMaxInMemoryCount, targetMaxTotalCount, capacityEvictionPolicyDataFactory); if (CacheConfigFactory.DSO_ACTIVE) { return new DistributedCacheImpl<K, V>(copyConfig); } else { return new LocalCache<K, V>(copyConfig); } }
/** * This method should always be called instead of System.currentTimeMillis() so that time can be controlled by the * TimeSource. * * @return The current time according to the TimeSource */ private int getTime() { return this.timeSource.now(); }
public TimestampedValue unlockedGetTimestampedValueQuiet(final K key) { return getNonExpiredEntryUnlocked(key, false); }
public SerializedEntry(final T deserialized, final byte[] serialized, final TimeSource timeSource) { this(deserialized, serialized, timeSource.now()); }