Sunday, September 16, 2012

Dynacache Tip: Dynamically skip cache for a page

The usual way most people diagnose DynaCache problems is by commenting out or removing the cache-entry or cache-id snippet in cachespec.xml. Since cachespec.xml changes are loaded without restarting, this works pretty well.

While this works fine, sometimes I want to be able to see what the page looks like without caching quickly, without having to edit cachespec.xml. Sometimes the changes to cachespec.xml would require creating a support ticket to modify a QA or DEV environment.

A more dynamic solution is to use a servlet filter to disable caching for a top level page without touching DynaCache.

Here is code for such a servlet filter:


This filter will disable caching when the URL contains the parameter "nocache" with value "true".
Example: http://localhost/webapp/wcs/stores/servlet/StoreCatalogDisplay?langId=-1&storeId=10151&catalogId=10551&nocache=true

Keep in mind that this only disables caching for the URL you are hitting in your browser and does not affect caching of child fragments which are not consumed by that URL.

This filter should only be used in DEV or QA environments.

No comments:

Post a Comment