1 package org.shiftone.cache.decorator.tandem; 2 3 4 5 import org.shiftone.cache.util.Log; 6 import org.shiftone.cache.Cache; 7 8 9 15 public class TandemCache implements Cache 16 { 17 18 private static final Log LOG = new Log(TandemCache.class); 19 protected final Cache[] caches; 20 21 public TandemCache(Cache[] caches) 22 { 23 this.caches = caches; 24 } 25 26 27 public void addObject(Object userKey, Object cacheObject) 28 { 29 30 for (int i = 0; i < caches.length; i++) 31 { 32 caches[i].addObject(userKey, cacheObject); 33 } 34 } 35 36 37 public Object getObject(Object key) 38 { 39 40 Object object = null; 41 42 for (int i = 0; i < caches.length; i++) 43 { 44 object = caches[i].getObject(key); 45 46 if (object != null) 47 { 48 return object; 49 } 50 } 51 52 return null; 53 } 54 55 56 public int size() 57 { 58 59 int max = 0; 60 61 for (int i = 0; i < caches.length; i++) 62 { 63 max = Math.max(max, caches[i].size()); 64 } 65 66 return max; 67 } 68 69 70 public void remove(Object key) 71 { 72 73 for (int i = 0; i < caches.length; i++) 74 { 75 caches[i].remove(key); 76 } 77 } 78 79 80 public void clear() 81 { 82 83 for (int i = 0; i < caches.length; i++) 84 { 85 caches[i].clear(); 86 } 87 } 88 } 89 | Popular Tags |