1
16
17 package net.sf.ehcache.store;
18
19 import net.sf.ehcache.CacheException;
20 import net.sf.ehcache.Ehcache;
21 import net.sf.ehcache.config.CacheConfiguration;
22 import net.sf.ehcache.pool.Pool;
23 import net.sf.ehcache.search.impl.SearchManager;
24 import net.sf.ehcache.store.disk.DiskStore;
25
26 import java.io.Serializable;
27
28
33 public final class DiskBackedMemoryStore extends FrontEndCacheTier<MemoryStore, DiskStore> {
34
35 private DiskBackedMemoryStore(CacheConfiguration cacheConfiguration, MemoryStore cache, DiskStore authority, SearchManager searchManager) {
36 super(cache, authority, cacheConfiguration.getCopyStrategy(), searchManager,
37 cacheConfiguration.isCopyOnWrite(), cacheConfiguration.isCopyOnRead());
38 }
39
40
47 public static Store create(Ehcache cache, Pool onHeapPool, Pool onDiskPool) {
48 final MemoryStore memoryStore = createMemoryStore(cache, onHeapPool);
49 DiskStore diskStore = createDiskStore(cache, onHeapPool, onDiskPool);
50
51 return new DiskBackedMemoryStore(cache.getCacheConfiguration(), memoryStore, diskStore, null);
52 }
53
54 private static MemoryStore createMemoryStore(Ehcache cache, Pool onHeapPool) {
55 return MemoryStore.create(cache, onHeapPool);
56 }
57
58 private static DiskStore createDiskStore(Ehcache cache, Pool onHeapPool, Pool onDiskPool) {
59 CacheConfiguration config = cache.getCacheConfiguration();
60 if (config.isOverflowToDisk()) {
61 return DiskStore.create(cache, onHeapPool, onDiskPool);
62 } else {
63 throw new CacheException("DiskBackedMemoryStore can only be used when cache overflows to disk or is disk persistent");
64 }
65 }
66
67
70 public Object getMBean() {
71 return null;
72 }
73
74
77 @Override
78 public boolean notifyEvictionFromCache(final Serializable key) {
79 return authority.cleanUpFailedMarker(key);
80 }
81 }
82