Always do a (potentially distributed) cache remove on invalidation, regardless of what's in the local cache. From Kyle Sampson.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2335 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
zell
2008-07-17 12:16:39 +00:00
parent fbce967233
commit 744c4cf3d5
@@ -371,28 +371,25 @@ public class PersistenceContext
CacheAdapter.CacheBin<T> bin = _cache.getCache(cacheId); CacheAdapter.CacheBin<T> bin = _cache.getCache(cacheId);
CacheAdapter.CachedValue<T> element = bin.lookup(cacheKey); CacheAdapter.CachedValue<T> element = bin.lookup(cacheKey);
if (element == null) { if (element != null) {
return; // find the old entry, if any
} T oldEntry = element.getValue();
if (oldEntry != null) {
// find the old entry, if any // if there was one, do (possibly cascading) cache invalidations
T oldEntry = element.getValue(); Set<CacheListener<?>> listeners = _listenerSets.get(cacheId);
if (oldEntry != null) { if (listeners != null && listeners.size() > 0) {
// if there was one, do (possibly cascading) cache invalidations CacheKey key = new SimpleCacheKey(cacheId, cacheKey);
Set<CacheListener<?>> listeners = _listenerSets.get(cacheId); for (CacheListener<?> listener : listeners) {
if (listeners != null && listeners.size() > 0) { log.debug("cascading [listener=" + listener + "]");
CacheKey key = new SimpleCacheKey(cacheId, cacheKey); @SuppressWarnings("unchecked") CacheListener<T> casted =
for (CacheListener<?> listener : listeners) { (CacheListener<T>)listener;
log.debug("cascading [listener=" + listener + "]"); casted.entryInvalidated(key, oldEntry);
@SuppressWarnings("unchecked") CacheListener<T> casted = }
(CacheListener<T>)listener;
casted.entryInvalidated(key, oldEntry);
} }
} }
} }
// then evict the keyed entry, if needed // then remove the keyed entry from the cache system
log.debug("evicting [cacheKey=" + cacheKey + "]");
bin.remove(cacheKey); bin.remove(cacheKey);
} }