01: package net.sf.ehcache.store;
02:
03: import org.apache.commons.logging.Log;
04: import org.apache.commons.logging.LogFactory;
05:
06: /**
07: * This is a modification of the Ehcache net.sf.ehcache.store.MemoryStoreEvictionPolicy.java class, which is
08: * under the Apache open source license.
09: *
10: */
11: /**
12: * A typesafe enumeration of eviction policies. The policy used to evict elements from the
13: * {@link net.sf.ehcache.store.MemoryStore}. This can be one of:
14: * <ol>
15: * <li>LRU - least recently used
16: * <li>LFU - least frequently used
17: * <li>FIFO - first in first out, the oldest element by creation time
18: * <li>DSO - a time based eviction policy implemented by Terracotta
19: * </ol>
20: * The default value is LRU
21: *
22: * @author <a href="mailto:gluck@thoughtworks.com">Greg Luck</a>
23: * @version $Id: MemoryStoreEvictionPolicyTC.java 5280 2007-08-27 18:23:11Z asi $
24: * @since 1.2
25: */
26: public final class MemoryStoreEvictionPolicyTC {
27:
28: /**
29: * LRU - least recently used.
30: */
31: public static final MemoryStoreEvictionPolicyTC LRU = new MemoryStoreEvictionPolicyTC(
32: "LRU");
33:
34: /**
35: * LFU - least frequently used.
36: */
37:
38: public static final MemoryStoreEvictionPolicyTC LFU = new MemoryStoreEvictionPolicyTC(
39: "LFU");
40:
41: /**
42: * FIFO - first in first out, the oldest element by creation time.
43: */
44: public static final MemoryStoreEvictionPolicyTC FIFO = new MemoryStoreEvictionPolicyTC(
45: "FIFO");
46:
47: public static final MemoryStoreEvictionPolicyTC DSO = new MemoryStoreEvictionPolicyTC(
48: "DSO");
49:
50: private static final Log LOG = LogFactory
51: .getLog(MemoryStoreEvictionPolicy.class.getName());
52:
53: // for debug only
54: private final String myName;
55:
56: /**
57: * This class should not be subclassed or have instances created.
58: *
59: * @param policy
60: */
61: private MemoryStoreEvictionPolicyTC(String policy) {
62: myName = policy;
63: }
64:
65: /**
66: * @return a String representation of the policy
67: */
68: public String toString() {
69: return myName;
70: }
71:
72: /**
73: * Converts a string representation of the policy into a policy.
74: *
75: * @param policy either LRU, LFU or FIFO
76: * @return one of the static instances
77: */
78: public static MemoryStoreEvictionPolicyTC fromString(String policy) {
79: if (policy != null) {
80: if (policy.equalsIgnoreCase("LRU")) {
81: return LRU;
82: } else if (policy.equalsIgnoreCase("LFU")) {
83: return LFU;
84: } else if (policy.equalsIgnoreCase("FIFO")) {
85: return FIFO;
86: } else if (policy.equalsIgnoreCase("DSO")) {
87: return DSO;
88: }
89: }
90:
91: if (LOG.isWarnEnabled()) {
92: LOG.warn("The memoryStoreEvictionPolicy of " + policy
93: + " cannot be resolved. The policy will be"
94: + " set to LRU");
95: }
96: return LRU;
97: }
98: }
|