1 43 package net.jforum.cache; 44 45 import java.util.ArrayList ; 46 import java.util.Collection ; 47 import java.util.HashMap ; 48 import java.util.Map ; 49 50 54 public class DefaultCacheEngine implements CacheEngine 55 { 56 private Map cache = new HashMap (); 57 58 61 public void add(String key, Object value) 62 { 63 this.cache.put(key, value); 64 } 65 66 69 public void add(String fqn, String key, Object value) 70 { 71 Map m = (Map )this.cache.get(fqn); 72 if (m == null) { 73 m = new HashMap (); 74 } 75 76 m.put(key, value); 77 this.cache.put(fqn, m); 78 } 79 80 83 public Object get(String fqn, String key) 84 { 85 Map m = (Map )this.cache.get(fqn); 86 if (m == null) { 87 return null; 88 } 89 90 return m.get(key); 91 } 92 93 96 public Object get(String fqn) 97 { 98 return this.cache.get(fqn); 99 } 100 101 104 public Collection getValues(String fqn) 105 { 106 Map m = (Map )this.cache.get(fqn); 107 if (m == null) { 108 return new ArrayList (); 109 } 110 111 return m.values(); 112 } 113 114 117 public void init() 118 { 119 this.cache = new HashMap (); 120 } 121 122 125 public void stop() {} 126 127 130 public void remove(String fqn, String key) 131 { 132 Map m = (Map )this.cache.get(fqn); 133 if (m != null) { 134 m.remove(key); 135 } 136 } 137 138 141 public void remove(String fqn) 142 { 143 this.cache.remove(fqn); 144 } 145 } 146 | Popular Tags |