01: package org.shiftone.cache.adaptor;
02:
03: import org.shiftone.cache.Cache;
04:
05: /**
06: * Makes a ORO cache look like a shiftone cache.
07: * <p>
08: * <b>Notes</b>
09: * <li>No support for remove
10: * <li>No support for clear
11: * <li>No support for node expiration
12: * <li>Cache initially allocates array of size "capacity"
13: *
14: * @version $Revision: 1.5 $
15: * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
16: */
17: public class OroCache implements Cache {
18:
19: private final org.apache.oro.util.Cache cache;
20:
21: public static Cache createFIFO(int capacity) {
22: return new OroCache(new org.apache.oro.util.CacheFIFO(capacity));
23: }
24:
25: public static Cache createFIFO2(int capacity) {
26: return new OroCache(
27: new org.apache.oro.util.CacheFIFO2(capacity));
28: }
29:
30: public static Cache createLRU(int capacity) {
31: return new OroCache(new org.apache.oro.util.CacheLRU(capacity));
32: }
33:
34: public static Cache createRandom(int capacity) {
35: return new OroCache(new org.apache.oro.util.CacheRandom(
36: capacity));
37: }
38:
39: public OroCache(org.apache.oro.util.Cache cache) {
40: this .cache = cache;
41: }
42:
43: public void addObject(Object userKey, Object cacheObject) {
44: cache.addElement(userKey, cacheObject);
45: }
46:
47: public Object getObject(Object key) {
48: return cache.getElement(key);
49: }
50:
51: public int size() {
52: return cache.size();
53: }
54:
55: /**
56: * NOOP
57: */
58: public void remove(Object key) {
59: }
60:
61: /**
62: * NOOP
63: */
64: public void clear() {
65: }
66:
67: public String toString() {
68: return "OroCache[" + cache.getClass().getName() + ":"
69: + cache.capacity() + "]";
70: }
71: }
|