01: package org.shiftone.cache.decorator.tandem;
02:
03: import org.shiftone.cache.util.Log;
04: import org.shiftone.cache.Cache;
05:
06: /**
07: * This cache will stop asking cache's for values once one of them
08: * returns a non null response.
09: * @version $Revision: 1.1 $
10: * @author $Author: jeffdrost $
11: */
12: public class TandemCache implements Cache {
13:
14: private static final Log LOG = new Log(TandemCache.class);
15: protected final Cache[] caches;
16:
17: public TandemCache(Cache[] caches) {
18: this .caches = caches;
19: }
20:
21: public void addObject(Object userKey, Object cacheObject) {
22:
23: for (int i = 0; i < caches.length; i++) {
24: caches[i].addObject(userKey, cacheObject);
25: }
26: }
27:
28: public Object getObject(Object key) {
29:
30: Object object = null;
31:
32: for (int i = 0; i < caches.length; i++) {
33: object = caches[i].getObject(key);
34:
35: if (object != null) {
36: return object;
37: }
38: }
39:
40: return null;
41: }
42:
43: public int size() {
44:
45: int max = 0;
46:
47: for (int i = 0; i < caches.length; i++) {
48: max = Math.max(max, caches[i].size());
49: }
50:
51: return max;
52: }
53:
54: public void remove(Object key) {
55:
56: for (int i = 0; i < caches.length; i++) {
57: caches[i].remove(key);
58: }
59: }
60:
61: public void clear() {
62:
63: for (int i = 0; i < caches.length; i++) {
64: caches[i].clear();
65: }
66: }
67: }
|