I made mach-ii plugin to manage the keys for cached content. Plugin has 2 parameters,
first is a name of event arg that has content to store in cache, second is an event to announce if there is cached content.
Here is most of the code for the plugin with makeCacheKey() method omitted because it would be different for others, the main thing is that it returns a string with a key or empty string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction name="preProcess" access="public" returntype="void" output="false"> | |
<cfargument name="eventContext" type="MachII.framework.EventContext" required="true" /> | |
<cfscript> | |
var e = arguments.eventContext.getNextEvent(); | |
var key = makeCacheKey(e); | |
var cacheData = ''; | |
//get data from cache | |
if(key neq '') { | |
cacheData = variables.EhCacheManager.get(key); | |
if(cacheData neq '') { | |
e.setArg(getParameter("contentEventArg"),cacheData); | |
e.setArg("isFromCache",'true'); | |
arguments.eventContext.clearEventQueue(); | |
arguments.eventContext.announceEvent(getParameter("eventToAnnounce"),e.getArgs()); | |
} | |
} | |
</cfscript> | |
</cffunction> | |
<cffunction name="postProcess" access="public" returntype="void" output="false"> | |
<cfargument name="eventContext" type="MachII.framework.EventContext" required="true" /> | |
<cfscript> | |
var e = arguments.eventContext.getCurrentEvent(); | |
var key = makeCacheKey(e); | |
var cacheData = e.getArg(getParameter("contentEventArg")); | |
var cacheKeys = arrayToList(variables.EhCacheManager.getCurrentCacheKeys()); | |
//put data into cache | |
if(cacheData neq '' And Not listFindNoCase(cacheKeys,key)) { | |
variables.EhCacheManager.put(key,cacheData); | |
} | |
</cfscript> | |
</cffunction> |