1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.caches.memcached;
17
18 import java.util.concurrent.locks.ReadWriteLock;
19
20 import org.apache.ibatis.cache.Cache;
21
22
23
24
25
26
27 public final class MemcachedCache implements Cache {
28
29 private static final MemcachedClientWrapper MEMCACHED_CLIENT = new MemcachedClientWrapper();
30
31
32
33
34 private final ReadWriteLock readWriteLock = new DummyReadWriteLock();
35
36
37
38
39 private final String id;
40
41
42
43
44
45
46
47 public MemcachedCache(final String id) {
48 this.id = id;
49 }
50
51
52
53
54 @Override
55 public void clear() {
56 MEMCACHED_CLIENT.removeGroup(this.id);
57 }
58
59
60
61
62 @Override
63 public String getId() {
64 return this.id;
65 }
66
67
68
69
70 @Override
71 public Object getObject(Object key) {
72 return MEMCACHED_CLIENT.getObject(key);
73 }
74
75
76
77
78 @Override
79 public ReadWriteLock getReadWriteLock() {
80 return this.readWriteLock;
81 }
82
83
84
85
86 @Override
87 public int getSize() {
88 return Integer.MAX_VALUE;
89 }
90
91
92
93
94 @Override
95 public void putObject(Object key, Object value) {
96 MEMCACHED_CLIENT.putObject(key, value, this.id);
97 }
98
99
100
101
102 @Override
103 public Object removeObject(Object key) {
104 return MEMCACHED_CLIENT.removeObject(key);
105 }
106
107 }