1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.cache.decorators;
17
18 import java.util.concurrent.locks.ReentrantLock;
19
20 import org.apache.ibatis.cache.Cache;
21
22
23
24
25 public class SynchronizedCache implements Cache {
26
27 private final ReentrantLock lock = new ReentrantLock();
28 private final Cache delegate;
29
30 public SynchronizedCache(Cache delegate) {
31 this.delegate = delegate;
32 }
33
34 @Override
35 public String getId() {
36 return delegate.getId();
37 }
38
39 @Override
40 public int getSize() {
41 lock.lock();
42 try {
43 return delegate.getSize();
44 } finally {
45 lock.unlock();
46 }
47 }
48
49 @Override
50 public void putObject(Object key, Object object) {
51 lock.lock();
52 try {
53 delegate.putObject(key, object);
54 } finally {
55 lock.unlock();
56 }
57 }
58
59 @Override
60 public Object getObject(Object key) {
61 lock.lock();
62 try {
63 return delegate.getObject(key);
64 } finally {
65 lock.unlock();
66 }
67 }
68
69 @Override
70 public Object removeObject(Object key) {
71 lock.lock();
72 try {
73 return delegate.removeObject(key);
74 } finally {
75 lock.unlock();
76 }
77 }
78
79 @Override
80 public void clear() {
81 lock.lock();
82 try {
83 delegate.clear();
84 } finally {
85 lock.unlock();
86 }
87 }
88
89 @Override
90 public int hashCode() {
91 return delegate.hashCode();
92 }
93
94 @Override
95 public boolean equals(Object obj) {
96 return delegate.equals(obj);
97 }
98
99 }