Allow a Key<T> to be invalidated directly and create the KeyCacheKey for the

caller.
This commit is contained in:
Michael Bayne
2009-07-30 23:23:18 +00:00
parent e876ff0832
commit 2ee38910c6
4 changed files with 20 additions and 4 deletions
+4 -2
View File
@@ -35,8 +35,10 @@ public interface CacheKey
public String getCacheId (); public String getCacheId ();
/** /**
* Returns the actual opaque serializable cache key under which results are stored * Returns the actual opaque serializable cache key under which results are stored in the cache
* in the cache identified by {@link #getCacheId}. * identified by {@link #getCacheId}. The object returned by this method should <em>only</em>
* reference system classes (not application classes). Depot takes care to ensure this and you
* probably aren't implementing your own cache keys so this should be fine.
*/ */
public Serializable getCacheKey (); public Serializable getCacheKey ();
} }
+1 -1
View File
@@ -214,7 +214,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
// from CacheInvalidator // from CacheInvalidator
public void invalidate (PersistenceContext ctx) public void invalidate (PersistenceContext ctx)
{ {
ctx.cacheInvalidate(new KeyCacheKey(this)); ctx.cacheInvalidate(this);
} }
/** /**
+1 -1
View File
@@ -300,7 +300,7 @@ public abstract class KeySet<T extends PersistentRecord> extends WhereClause
// from ValidatingCacheInvalidator // from ValidatingCacheInvalidator
public void invalidate (PersistenceContext ctx) { public void invalidate (PersistenceContext ctx) {
for (Key<T> key : this) { for (Key<T> key : this) {
ctx.cacheInvalidate(new KeyCacheKey(key)); ctx.cacheInvalidate(key);
} }
} }
@@ -45,6 +45,7 @@ import com.samskivert.depot.annotation.TableGenerator;
import com.samskivert.depot.impl.DepotMarshaller; import com.samskivert.depot.impl.DepotMarshaller;
import com.samskivert.depot.impl.DepotMetaData; import com.samskivert.depot.impl.DepotMetaData;
import com.samskivert.depot.impl.DepotTypes; import com.samskivert.depot.impl.DepotTypes;
import com.samskivert.depot.impl.KeyCacheKey;
import com.samskivert.depot.impl.Modifier; import com.samskivert.depot.impl.Modifier;
import com.samskivert.depot.impl.Operation; import com.samskivert.depot.impl.Operation;
import com.samskivert.depot.impl.Query; import com.samskivert.depot.impl.Query;
@@ -349,6 +350,19 @@ public class PersistenceContext
} }
} }
/**
* Evicts the cache entry indexed under the given key, if there is one. The eviction may
* trigger further cache invalidations.
*/
public void cacheInvalidate (Key<?> key)
{
if (key == null) {
log.warning("Cache key to invalidate must not be null.", new Exception());
} else {
cacheInvalidate(new KeyCacheKey(key));
}
}
/** /**
* Evicts the cache entry indexed under the given key, if there is one. The eviction may * Evicts the cache entry indexed under the given key, if there is one. The eviction may
* trigger further cache invalidations. * trigger further cache invalidations.