From eac0e214efbd785f241e9233ff5c58e72d1d8bfb Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Thu, 17 Jul 2008 12:16:39 +0000 Subject: [PATCH] Always do a (potentially distributed) cache remove on invalidation, regardless of what's in the local cache. From Kyle Sampson. --- .../jdbc/depot/PersistenceContext.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/PersistenceContext.java b/src/java/com/samskivert/jdbc/depot/PersistenceContext.java index d4b266c..518ccfd 100644 --- a/src/java/com/samskivert/jdbc/depot/PersistenceContext.java +++ b/src/java/com/samskivert/jdbc/depot/PersistenceContext.java @@ -371,28 +371,25 @@ public class PersistenceContext CacheAdapter.CacheBin bin = _cache.getCache(cacheId); CacheAdapter.CachedValue element = bin.lookup(cacheKey); - if (element == null) { - return; - } - - // find the old entry, if any - T oldEntry = element.getValue(); - if (oldEntry != null) { - // if there was one, do (possibly cascading) cache invalidations - Set> listeners = _listenerSets.get(cacheId); - if (listeners != null && listeners.size() > 0) { - CacheKey key = new SimpleCacheKey(cacheId, cacheKey); - for (CacheListener listener : listeners) { - log.debug("cascading [listener=" + listener + "]"); - @SuppressWarnings("unchecked") CacheListener casted = - (CacheListener)listener; - casted.entryInvalidated(key, oldEntry); + if (element != null) { + // find the old entry, if any + T oldEntry = element.getValue(); + if (oldEntry != null) { + // if there was one, do (possibly cascading) cache invalidations + Set> listeners = _listenerSets.get(cacheId); + if (listeners != null && listeners.size() > 0) { + CacheKey key = new SimpleCacheKey(cacheId, cacheKey); + for (CacheListener listener : listeners) { + log.debug("cascading [listener=" + listener + "]"); + @SuppressWarnings("unchecked") CacheListener casted = + (CacheListener)listener; + casted.entryInvalidated(key, oldEntry); + } } } } - // then evict the keyed entry, if needed - log.debug("evicting [cacheKey=" + cacheKey + "]"); + // then remove the keyed entry from the cache system bin.remove(cacheKey); }