Http Cache - Handling rules

« back to HTTP Cache Table of Contents

Configuring global rules on the cache engine (HttpCacheEngineImpl)

Central controlling unit for http cache.
Define a sling:OsgiConfig /apps/mysite/config/com.adobe.acs.commons.httpcache.engine.impl.HttpCacheEngineImpl.xml

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="" xmlns:cq=""
    xmlns:jcr="" xmlns:nt=""
    jcr:primaryType="sling:OsgiConfig""[pid-of-rule-1, pid-of-rule-2, pid-of-rule-3]"

Creating a new global cache handling rule

Cache handling rules provide touch-points to plug in custom logic on key cache handling events. They are modeled as OSGi services implementing com.adobe.acs.commons.httpcache.rule.HttpCacheHandlingRule. The contract is that the current cache action will be continued only if the methods implementing the interface returns true. A convenient abstract class com.adobe.acs.commons.httpcache.rule.AbstractHttpCacheHandlingRule has been provided facilitating the sub classes to override just the intended methods. The best practice is to have a rule overriding just one method.

Event Method OOTB rules
On qualifying http requests onRequestReceive com.adobe.acs.commons.httpcache.rule.impl.CacheOnlyGetRequest, com.adobe.acs.commons.httpcache.rule.impl.DoNotCacheRequestWithQueryString
On caching the response onResponseCache com.adobe.acs.commons.httpcache.rule.impl.CacheOnlyResponse200, com.adobe.acs.commons.httpcache.rule.impl.DoNotCacheZeroSizeResponse, com.adobe.acs.commons.httpcache.rule.impl.HonorCacheControlHeaders
On delivering from cache onCacheDeliver com.adobe.acs.commons.httpcache.rule.impl.MarkResponseAsCacheDelivered
On invalidating the cache onCacheInvalidate  

Rules which are configured to of com.adobe.acs.commons.httpcache.engine.impl.HttpCacheEngineImpl are applicable for all cache configs (hence, all cache-able requests) and called global cache handling rules.

  • Set of service pid of global cache handling rules. These rules are applied to all cache configs and hence all cache-able requests.

Creating new config specific cache handling rule

Any cache handling rule explained above applied only to specific cache config via of com.adobe.acs.commons.httpcache.config.impl.HttpCacheConfigImpl is called cache config specific rule.

Please report any issues with the Feature or documentation on the ACS AEM Commons GitHub Issue tracker.