diff --git a/src/java/com/samskivert/depot/CacheKey.java b/src/java/com/samskivert/depot/CacheKey.java index 4c5d735..d84a234 100644 --- a/src/java/com/samskivert/depot/CacheKey.java +++ b/src/java/com/samskivert/depot/CacheKey.java @@ -35,8 +35,10 @@ public interface CacheKey public String getCacheId (); /** - * Returns the actual opaque serializable cache key under which results are stored - * in the cache identified by {@link #getCacheId}. + * Returns the actual opaque serializable cache key under which results are stored in the cache + * identified by {@link #getCacheId}. The object returned by this method should only + * 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 (); } diff --git a/src/java/com/samskivert/depot/Key.java b/src/java/com/samskivert/depot/Key.java index 46ff283..b91ff71 100644 --- a/src/java/com/samskivert/depot/Key.java +++ b/src/java/com/samskivert/depot/Key.java @@ -214,7 +214,7 @@ public class Key extends WhereClause // from CacheInvalidator public void invalidate (PersistenceContext ctx) { - ctx.cacheInvalidate(new KeyCacheKey(this)); + ctx.cacheInvalidate(this); } /** diff --git a/src/java/com/samskivert/depot/KeySet.java b/src/java/com/samskivert/depot/KeySet.java index fd17a34..9754cca 100644 --- a/src/java/com/samskivert/depot/KeySet.java +++ b/src/java/com/samskivert/depot/KeySet.java @@ -300,7 +300,7 @@ public abstract class KeySet extends WhereClause // from ValidatingCacheInvalidator public void invalidate (PersistenceContext ctx) { for (Key key : this) { - ctx.cacheInvalidate(new KeyCacheKey(key)); + ctx.cacheInvalidate(key); } } diff --git a/src/java/com/samskivert/depot/PersistenceContext.java b/src/java/com/samskivert/depot/PersistenceContext.java index 65d905d..d9d080a 100644 --- a/src/java/com/samskivert/depot/PersistenceContext.java +++ b/src/java/com/samskivert/depot/PersistenceContext.java @@ -45,6 +45,7 @@ import com.samskivert.depot.annotation.TableGenerator; import com.samskivert.depot.impl.DepotMarshaller; import com.samskivert.depot.impl.DepotMetaData; import com.samskivert.depot.impl.DepotTypes; +import com.samskivert.depot.impl.KeyCacheKey; import com.samskivert.depot.impl.Modifier; import com.samskivert.depot.impl.Operation; 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 * trigger further cache invalidations.