diff --git a/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java b/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java index 0fec7ce..034fdc3 100644 --- a/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java +++ b/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java @@ -20,6 +20,8 @@ package com.samskivert.jdbc.depot; +import java.io.Serializable; + /** * Implementors of this interface performs perform cache invalidation for calls to * {@link DepotRepository#updateLiteral}, {@link DepotRepository#updatePartial} and @@ -27,6 +29,30 @@ package com.samskivert.jdbc.depot; */ public interface CacheInvalidator { + public static abstract class TraverseWithFilter + implements CacheInvalidator + { + public TraverseWithFilter (Class pClass) { + this(pClass.getName()); + } + + public TraverseWithFilter (String cacheId) { + _cacheId = cacheId; + } + + public void invalidate (PersistenceContext ctx) { + ctx.cacheTraverse(_cacheId, new PersistenceContext.CacheEvictionFilter() { + protected boolean testForEviction (Serializable key, T record) { + return TraverseWithFilter.this.testForEviction(key, record); + } + }); + } + + protected abstract boolean testForEviction (Serializable key, T record); + + protected String _cacheId; + } + /** * Must invalidate all cache entries that depend on the records being modified or deleted. * This method is called just before the database statement is executed.