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 {
5959 Object getObject (Object key );
6060
6161 /**
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+ *
6371 *
6472 * @param key The key
65- * @return The object that was removed
73+ * @return Not used
6674 */
6775 Object removeObject (Object key );
6876
Original file line number Diff line number Diff line change 2727/**
2828 * Simple blocking decorator
2929 *
30- * Sipmle and inefficient version of EhCache's BlockingCache decorator.
30+ * Simple and inefficient version of EhCache's BlockingCache decorator.
3131 * It sets a lock over a cache key when the element is not found in cache.
3232 * This way, other threads will wait until this element is filled instead of hitting the database.
3333 *
@@ -76,7 +76,9 @@ public Object getObject(Object key) {
7676
7777 @ Override
7878 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 ;
8082 }
8183
8284 @ Override
Original file line number Diff line number Diff line change 2222import java .util .concurrent .locks .ReadWriteLock ;
2323
2424import org .apache .ibatis .cache .Cache ;
25+ import org .apache .ibatis .logging .Log ;
26+ import org .apache .ibatis .logging .LogFactory ;
2527
2628/**
2729 * The 2nd level cache transactional buffer.
3638 */
3739public class TransactionalCache implements Cache {
3840
41+ private static final Log log = LogFactory .getLog (TransactionalCache .class );
42+
3943 private Cache delegate ;
4044 private boolean clearOnCommit ;
4145 private Map <Object , Object > entriesToAddOnCommit ;
@@ -126,7 +130,12 @@ private void flushPendingEntries() {
126130
127131 private void unlockMissedEntries () {
128132 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+ }
130139 }
131140 }
132141
You can’t perform that action at this time.
0 commit comments