1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.cache.impl;
17
18 import java.util.HashMap;
19 import java.util.Map;
20 import java.util.concurrent.locks.ReadWriteLock;
21
22 import org.apache.ibatis.cache.Cache;
23 import org.apache.ibatis.cache.CacheException;
24
25
26
27
28 public class PerpetualCache implements Cache {
29
30 private String id;
31
32 private Map<Object, Object> cache = new HashMap<Object, Object>();
33
34 public PerpetualCache(String id) {
35 this.id = id;
36 }
37
38 @Override
39 public String getId() {
40 return id;
41 }
42
43 @Override
44 public int getSize() {
45 return cache.size();
46 }
47
48 @Override
49 public void putObject(Object key, Object value) {
50 cache.put(key, value);
51 }
52
53 @Override
54 public Object getObject(Object key) {
55 return cache.get(key);
56 }
57
58 @Override
59 public Object removeObject(Object key) {
60 return cache.remove(key);
61 }
62
63 @Override
64 public void clear() {
65 cache.clear();
66 }
67
68 @Override
69 public ReadWriteLock getReadWriteLock() {
70 return null;
71 }
72
73 @Override
74 public boolean equals(Object o) {
75 if (getId() == null) {
76 throw new CacheException("Cache instances require an ID.");
77 }
78 if (this == o) {
79 return true;
80 }
81 if (!(o instanceof Cache)) {
82 return false;
83 }
84
85 Cache otherCache = (Cache) o;
86 return getId().equals(otherCache.getId());
87 }
88
89 @Override
90 public int hashCode() {
91 if (getId() == null) {
92 throw new CacheException("Cache instances require an ID.");
93 }
94 return getId().hashCode();
95 }
96
97 }