1 package org.hibernate.cache; 3 4 import java.util.Collections ; 5 import java.util.Hashtable ; 6 7 import java.util.Map ; 8 9 13 public class HashtableCache implements Cache { 14 15 private final Map hashtable = new Hashtable (); 16 private final String regionName; 17 18 public HashtableCache(String regionName) { 19 this.regionName = regionName; 20 } 21 22 public String getRegionName() { 23 return regionName; 24 } 25 26 public Object read(Object key) throws CacheException { 27 return hashtable.get(key); 28 } 29 30 public Object get(Object key) throws CacheException { 31 return hashtable.get(key); 32 } 33 34 public void update(Object key, Object value) throws CacheException { 35 put(key, value); 36 } 37 38 public void put(Object key, Object value) throws CacheException { 39 hashtable.put(key, value); 40 } 41 42 public void remove(Object key) throws CacheException { 43 hashtable.remove(key); 44 } 45 46 public void clear() throws CacheException { 47 hashtable.clear(); 48 } 49 50 public void destroy() throws CacheException { 51 52 } 53 54 public void lock(Object key) throws CacheException { 55 } 57 58 public void unlock(Object key) throws CacheException { 59 } 61 62 public long nextTimestamp() { 63 return Timestamper.next(); 64 } 65 66 public int getTimeout() { 67 return Timestamper.ONE_MS * 60000; } 69 70 public long getSizeInMemory() { 71 return -1; 72 } 73 74 public long getElementCountInMemory() { 75 return hashtable.size(); 76 } 77 78 public long getElementCountOnDisk() { 79 return 0; 80 } 81 82 public Map toMap() { 83 return Collections.unmodifiableMap(hashtable); 84 } 85 86 public String toString() { 87 return "HashtableCache(" + regionName + ')'; 88 } 89 90 } 91 | Popular Tags |