This is an automated email from the ASF dual-hosted git repository. johnthuss pushed a commit to branch ics17 in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 780f303edb34db178ee247b7846be879698b2ace Author: John Huss <[email protected]> AuthorDate: Tue Jan 29 16:54:19 2019 -0600 Allow CacheInvalidationFilter to be enabled/disabled on a per context basis --- .../cayenne/cache/invalidation/CacheInvalidationFilter.java | 5 ++++- .../main/java/org/apache/cayenne/configuration/Constants.java | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java index 2d7eb15..b3f11b5 100644 --- a/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java +++ b/cayenne-cache-invalidation/src/main/java/org/apache/cayenne/cache/invalidation/CacheInvalidationFilter.java @@ -27,6 +27,7 @@ import org.apache.cayenne.annotation.PrePersist; import org.apache.cayenne.annotation.PreRemove; import org.apache.cayenne.annotation.PreUpdate; import org.apache.cayenne.cache.QueryCache; +import org.apache.cayenne.configuration.Constants; import org.apache.cayenne.di.Inject; import org.apache.cayenne.di.Provider; import org.apache.cayenne.graph.GraphDiff; @@ -81,8 +82,10 @@ public class CacheInvalidationFilter implements DataChannelSyncFilter { try { GraphDiff result = filterChain.onSync(originatingContext, changes, syncType); // no exceptions, flush... + boolean invalidationEnabled = !Boolean.FALSE.equals( + originatingContext.getUserProperty(Constants.QUERY_CACHE_INVALIDATION_ENABLED_PROPERTY)); Collection<CacheGroupDescriptor> groupSet = groups.get(); - if (groupSet != null && !groupSet.isEmpty()) { + if (invalidationEnabled && groupSet != null && !groupSet.isEmpty()) { QueryCache cache = cacheProvider.get(); for (CacheGroupDescriptor group : groupSet) { if (group.getKeyType() != Void.class) { diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java index 7eb45dc..143105b 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java @@ -18,6 +18,7 @@ ****************************************************************/ package org.apache.cayenne.configuration; +import org.apache.cayenne.ObjectContext; import org.apache.cayenne.di.Binder; /** @@ -142,6 +143,16 @@ public interface Constants { String QUERY_CACHE_SIZE_PROPERTY = "cayenne.querycache.size"; /** + * An boolean property allowing the CacheInvalidationFilter to be enabled/disabled on + * as needed for a particular ObjectContext. + * + * @see org.apache.cayenne.ObjectContext#setUserProperty(String, Object) + * + * @since 4.1 + */ + public String QUERY_CACHE_INVALIDATION_ENABLED_PROPERTY = "cayenne.querycache.invalidation.enabled"; + + /** * An optional name of the runtime DataDomain. If not specified (which is * normally the case), the name is inferred from the configuration name. *
