01: package org.shiftone.cache.adaptor;
02:
03: import net.sf.swarmcache.LRUCache;
04: import net.sf.swarmcache.ObjectCache;
05: import org.shiftone.cache.Cache;
06:
07: import java.io.Serializable;
08:
09: /**
10: * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
11: * @version $Revision: 1.6 $
12: */
13: public class SwarmCache implements Cache {
14:
15: private final ObjectCache cache;
16:
17: public SwarmCache(int size) {
18:
19: LRUCache lruCache = new LRUCache();
20:
21: lruCache.setSize(size);
22:
23: this .cache = lruCache;
24: }
25:
26: public SwarmCache(ObjectCache cache) {
27: this .cache = cache;
28: }
29:
30: public void addObject(Object userKey, Object cacheObject) {
31: cache.put((Serializable) userKey, cacheObject);
32: }
33:
34: public Object getObject(Object key) {
35: return cache.get((Serializable) key);
36: }
37:
38: /**
39: * NOOP
40: */
41: public int size() {
42: return -1;
43: }
44:
45: public void remove(Object key) {
46: cache.clear((Serializable) key);
47: }
48:
49: public void clear() {
50: cache.clearAll();
51: }
52:
53: public String toString() {
54: return "SwarmCache[" + cache.getClass().getName() + "]";
55: }
56: }
|