File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed
src/main/java/org/apache/ibatis/cache Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -59,10 +59,18 @@ public interface Cache {
59
59
Object getObject (Object key );
60
60
61
61
/**
62
- * Optional. It is not called by the core.
62
+ * As of 3.3.0 this method is only called during a rollback
63
+ * for any previous value that was missing in the cache.
64
+ * This lets any blocking cache to release the lock that
65
+ * may have previously put on the key.
66
+ * A blocking cache puts a lock when a value is null
67
+ * and releases it when the value is back again.
68
+ * This way other threads will wait for the value to be
69
+ * available instead of hitting the database.
70
+ *
63
71
*
64
72
* @param key The key
65
- * @return The object that was removed
73
+ * @return Not used
66
74
*/
67
75
Object removeObject (Object key );
68
76
Original file line number Diff line number Diff line change 27
27
/**
28
28
* Simple blocking decorator
29
29
*
30
- * Sipmle and inefficient version of EhCache's BlockingCache decorator.
30
+ * Simple and inefficient version of EhCache's BlockingCache decorator.
31
31
* It sets a lock over a cache key when the element is not found in cache.
32
32
* This way, other threads will wait until this element is filled instead of hitting the database.
33
33
*
@@ -76,7 +76,9 @@ public Object getObject(Object key) {
76
76
77
77
@ Override
78
78
public Object removeObject (Object key ) {
79
- return delegate .removeObject (key );
79
+ // despite of its name, this method is called only to release locks
80
+ releaseLock (key );
81
+ return null ;
80
82
}
81
83
82
84
@ Override
Original file line number Diff line number Diff line change 22
22
import java .util .concurrent .locks .ReadWriteLock ;
23
23
24
24
import org .apache .ibatis .cache .Cache ;
25
+ import org .apache .ibatis .logging .Log ;
26
+ import org .apache .ibatis .logging .LogFactory ;
25
27
26
28
/**
27
29
* The 2nd level cache transactional buffer.
36
38
*/
37
39
public class TransactionalCache implements Cache {
38
40
41
+ private static final Log log = LogFactory .getLog (TransactionalCache .class );
42
+
39
43
private Cache delegate ;
40
44
private boolean clearOnCommit ;
41
45
private Map <Object , Object > entriesToAddOnCommit ;
@@ -126,7 +130,12 @@ private void flushPendingEntries() {
126
130
127
131
private void unlockMissedEntries () {
128
132
for (Object entry : entriesMissedInCache ) {
129
- delegate .putObject (entry , null );
133
+ try {
134
+ delegate .removeObject (entry );
135
+ } catch (Exception e ) {
136
+ log .warn ("Unexpected exception while notifiying a rollback to the cache adapter."
137
+ + "Consider upgrading your cache adapter to the latest version. Cause: " + e );
138
+ }
130
139
}
131
140
}
132
141
You can’t perform that action at this time.
0 commit comments