Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
/**
* Copyright Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.ehcache.store.cachingtier;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.config.AbstractCacheConfigurationListener;
import net.sf.ehcache.config.PinningConfiguration;
import net.sf.ehcache.config.SizeOfPolicyConfiguration;
import net.sf.ehcache.pool.Pool;
import net.sf.ehcache.pool.Size;
import net.sf.ehcache.pool.SizeOfEngine;
import net.sf.ehcache.pool.SizeOfEngineLoader;
import net.sf.ehcache.pool.sizeof.annotations.IgnoreSizeOf;
import net.sf.ehcache.store.CachingTier;
import net.sf.ehcache.store.FifoPolicy;
import net.sf.ehcache.store.LfuPolicy;
import net.sf.ehcache.store.LruPolicy;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import net.sf.ehcache.store.Policy;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import net.sf.ehcache.store.StoreOperationOutcomes.GetOutcome;
import net.sf.ehcache.store.StoreOperationOutcomes.PutOutcome;
import net.sf.ehcache.store.StoreOperationOutcomes.RemoveOutcome;
import org.terracotta.context.annotations.ContextChild;
import org.terracotta.statistics.Statistic;
import org.terracotta.statistics.observer.OperationObserver;
import static net.sf.ehcache.statistics.StatisticBuilder.operation;
/**
* An instance of this class will delegate the storage to the backing HeapCacheBackEnd.
*
Adding :
*
making sure only a single thread populates the cache for a given key at a time
*
translate calls to the eviction listeners
*
Add all the crap about sizing and stuff
*
*
* @param The key type
* @param the value type
* @author Alex Snaps
*/
public class OnHeapCachingTier implements CachingTier {
@ContextChild
private final HeapCacheBackEnd backEnd;
private final OperationObserver getObserver = operation(GetOutcome.class).named("get").of(this).tag("local-heap").build();
private final OperationObserver putObserver = operation(PutOutcome.class).named("put").of(this).tag("local-heap").build();
private final OperationObserver removeObserver = operation(RemoveOutcome.class).named("remove").of(this).tag("local-heap").build();
private volatile List> listeners = new CopyOnWriteArrayList>();
/**
* A Constructor
*
* @param backEnd the HeapCacheBackEnd that will back this CachingTier
*/
public OnHeapCachingTier(final HeapCacheBackEnd backEnd) {
this.backEnd = backEnd;
this.backEnd.registerEvictionCallback(new HeapCacheBackEnd.EvictionCallback() {
@Override
public void evicted(final K key, final Object value) {
final V v = getValue(value);
if (v != null) {
for (Listener listener : listeners) {
listener.evicted(key, v);
}
}
}
});
}
/**
* Factory method
* @param cache the cache we're planning to back
* @param onHeapPool the pool, if any, to use
* @return the OnHeapCachingTier properly configured for this cache
*/
public static OnHeapCachingTier