1 package org.shiftone.cache.adaptor; 2 3 4 5 import net.sf.swarmcache.LRUCache; 6 import net.sf.swarmcache.ObjectCache; 7 import org.shiftone.cache.Cache; 8 9 import java.io.Serializable ; 10 11 12 16 public class SwarmCache implements Cache 17 { 18 19 private final ObjectCache cache; 20 21 public SwarmCache(int size) 22 { 23 24 LRUCache lruCache = new LRUCache(); 25 26 lruCache.setSize(size); 27 28 this.cache = lruCache; 29 } 30 31 32 public SwarmCache(ObjectCache cache) 33 { 34 this.cache = cache; 35 } 36 37 38 public void addObject(Object userKey, Object cacheObject) 39 { 40 cache.put((Serializable ) userKey, cacheObject); 41 } 42 43 44 public Object getObject(Object key) 45 { 46 return cache.get((Serializable ) key); 47 } 48 49 50 53 public int size() 54 { 55 return -1; 56 } 57 58 59 public void remove(Object key) 60 { 61 cache.clear((Serializable ) key); 62 } 63 64 65 public void clear() 66 { 67 cache.clearAll(); 68 } 69 70 71 public String toString() 72 { 73 return "SwarmCache[" + cache.getClass().getName() + "]"; 74 } 75 } 76 | Popular Tags |