01: package org.shiftone.cache.adaptor;
02:
03: import org.shiftone.cache.Cache;
04: import org.shiftone.cache.CacheFactory;
05: import org.shiftone.cache.policy.zero.ZeroCacheFactory;
06: import org.shiftone.cache.util.Log;
07:
08: /**
09: * Factory for ORO cache policys.
10: *
11: * @version $Revision: 1.1 $
12: * @author $Author: jeffdrost $
13: */
14: public class OroCacheFactory implements CacheFactory {
15:
16: private static final Log LOG = new Log(OroCacheFactory.class);
17: public static String ALGORITHM_FIFO = "FIFO";
18: public static String ALGORITHM_FIFO2 = "FIFO2";
19: public static String ALGORITHM_LRU = "LRU";
20: public static String ALGORITHM_RANDOM = "RANDOM";
21: private String algorithm = ALGORITHM_LRU;
22:
23: public Cache newInstance(String cacheName,
24: long timeoutMilliSeconds, int maxSize) {
25:
26: if (ALGORITHM_FIFO.equalsIgnoreCase(algorithm)) {
27: return OroCache.createFIFO(maxSize);
28: } else if (ALGORITHM_FIFO2.equalsIgnoreCase(algorithm)) {
29: return OroCache.createFIFO2(maxSize);
30: } else if (ALGORITHM_LRU.equalsIgnoreCase(algorithm)) {
31: return OroCache.createLRU(maxSize);
32: } else if (ALGORITHM_RANDOM.equalsIgnoreCase(algorithm)) {
33: return OroCache.createRandom(maxSize);
34: } else {
35: LOG.info("unknown ORO cache algorithm : " + algorithm);
36:
37: return ZeroCacheFactory.NULL_CACHE;
38: }
39: }
40:
41: public String getAlgorithm() {
42: return algorithm;
43: }
44:
45: /**
46: * FIFO, FIFO2, LRU, RANDOM
47: */
48: public void setAlgorithm(String algorithm) {
49: this.algorithm = algorithm;
50: }
51: }
|