Caching - Clear Via Listener

13 views
Skip to first unread message

Derrick Jackson

unread,
Mar 9, 2010, 4:16:24 PM3/9/10
to mach-ii-for...@googlegroups.com
Afternoon Folks,

I'm hoping one of you can help me clear something up.  I have an event that is caching data by criteria and also have two event args that are used to get the cache aliases:

<event-arg name="cacheAlias_Sub" value="constituentDataSubmited" />
<event-arg name="cacheAlias_IP" value="constituentDataInProcess" />
<cache alias="constituentDataSubmited" criteria="${event.applicationUUID}">
<notify listener="applicantListener" method="getApplicants" resultArg="submittedApplicants" />
</cache>
<cache alias="constituentDataInProcess" criteria="${event.applicationUUID}">
<notify listener="applicantListener" method="getApplicants" resultArg="inProcessApplicants" />
</cache>

Prior to those two caches I notify a listener to see if I need to clear the caches:

<notify listener="appListener" method="clearCacheByAlias" />

I modified the cache clearing example from the IntroToCaching WIKI.  In my case, if the value of clearCache (which gets is value from the CV event arg) is "1"  then the two caches are to be cleared.  Here is my code:

<cffunction name="clearCacheByAlias" access="public" returntype="string" output="false">
<cfargument name="event" type="MachII.framework.Event" required="true">
       
     <cfset var cacheAlias_Sub = event.getArg('cacheAlias_Sub')/>
     <cfset var cacheAlias_IP = event.getArg('cacheAlias_IP')/>
     <cfset var cacheManager = ""/>
     <cfset var clearCache = arguments.event.getArg('cv',0) />
     <cfset var applicationUUID = arguments.event.getArg('applicationUUID') />
       
     <cfif clearCache>
     <cfset cacheManager = getAppManager().getCacheManager() />
        
          <cfset cacheManager.clearCachesByAlias(cacheAlias_Sub,arguments.event,applicationUUID)/>
          <cfset cacheManager.clearCachesByAlias(cacheAlias_IP,arguments.event,applicationUUID)/>
     </cfif>
</cffunction>

Even though at times I pass in cv=1 to the event neither cache is being updated.  I can't see/figure out what I'm missing.

Thanks
Derrick

Brian Pickens

unread,
Mar 10, 2010, 10:56:04 AM3/10/10
to Mach-II for CFML
Have you tried dumping 'clearCache' with an abort right after to make
sure the value is what it's supposed to be? That is where I would
start...

On Mar 9, 3:16 pm, Derrick Jackson <derrick.jackso...@gmail.com>
wrote:

Derrick Jackson

unread,
Mar 10, 2010, 11:35:10 AM3/10/10
to mach-ii-for...@googlegroups.com
Thanks Brian.  I had the contents of the event emailed to me to be sure clearCache was set to 1 when I needed it to be.  The value was in fact set to 1.  In that same email i decided to add the following:
<cfdump var="#cacheManager.isAliasDefined(cacheAlias_Sub)# - #cacheManager.isAliasDefined(cacheAlias_IP)#"> to see if my aliases even exists. However, I get the following error:  variables.aliases doesn't exist.

I was prompted to check the existence of my aliases when I was looking over the logging output and saw the following: 

MachII.framework.CacheManager

trace

CacheManager clear cache for alias 'constituentDataSubmited', exists: NO, criteria: FEECF20C-423D-4A41-846A3174C1A704A6


MachII.framework.CacheManager

trace

CacheManager clear cache for alias 'constituentDataInProcess', exists: NO, criteria: FEECF20C-423D-4A41-846A3174C1A704A6



Note it states that my two aliases do not exists.  Any thoughts on why the aliases do not exists?

--
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to mach-ii-for...@googlegroups.com
To unsubscribe from this group, send email to mach-ii-for-coldf...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
SVN: http://greatbiztoolsllc.svn.cvsdude.com/mach-ii/
Wiki / Documentation / Tickets: http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/

Brian Pickens

unread,
Mar 10, 2010, 11:51:44 AM3/10/10
to Mach-II for CFML
Well looking at the code you first posted, I'm not seeing the
strategyName attribute in your <cache/> nodes. Do you have your
defaultCacheName parameter defined? At this point I'm not sure whats
going on, we may need a MachII expert like Peter to chime in here. You
may want to post the cache property configuration as well.

On Mar 10, 10:35 am, Derrick Jackson <derrick.jackso...@gmail.com>
wrote:

Derrick Jackson

unread,
Mar 10, 2010, 12:16:44 PM3/10/10
to mach-ii-for...@googlegroups.com
I'm using the basic settings:  <property name="Caching" type="MachII.caching.CachingProperty"/>. I just switched to using multiple caching strategies and cached based on that.  in the listener I am now clearing by strategy name but this is not working either.  I find this very odd..

Peter J. Farrell

unread,
Mar 10, 2010, 12:46:21 PM3/10/10
to mach-ii-for...@googlegroups.com
Derrick,  are you using modules?  If so, you need to talk to the right CacheManager.  There is a CacheManager for each module.  If your listener is in the base app and you are using that listener in a module  via module inheritance, than your listener is going to be talking to base app CacheManager.  I think this is the case.

.pjf

Derrick Jackson said the following on 10/03/10 11:16:

Derrick Jackson

unread,
Mar 10, 2010, 1:04:55 PM3/10/10
to mach-ii-for...@googlegroups.com
Hey Peter,

The only module I have in my app is the Dashboard.  The listener is in the base app and is not being used in the Dashboard module.  What I did notice when I started using multiple caching strategies is the named strategy I want to clear on occasion never shows any hits in the dashboard.  The default strategy shows hits increasing but not "ConData_Cache" strategy.  I've included the event in question in case I'm doing things in there that I should not be.

<event-handler event="showApplication" access="public">
<event-arg name="pageTitle" value="Constituent Data" />
<execute subroutine="getApplicationData" />
<notify listener="appListener" method="clearCacheByAlias" /> (this is named clearCacheByAlias, but its actually clearing by strategy. I just forgot to change the name)
<cache strategy="ConData_Cache" criteria="${event.applicationUUID}" >
<event-arg name="applicantStatus" value="1" />

<notify listener="applicantListener" method="getApplicants" resultArg="submittedApplicants" />
<event-arg name="applicantStatus" value="0" />

<notify listener="applicantListener" method="getApplicants" resultArg="inProcessApplicants" />
</cache>
<cache alias="constituentDataQuestion" criteria="${event.applicationUUID}">
<notify listener="questionListener" method="getQuestionsByApplicationUUID" resultArg="questionList"/>
<notify listener="answerListener" method="getAnswersToQuestions" resultArg="questionAnswerList" />
<notify listener="answerListener" method="getAnswersByApplicationUUID" resultArg="constituentAnswers"/>
</cache>
<view-page name="constituentData.applicantList" contentArg="content" />
<execute subroutine="mainTemplate" />
</event-handler>

Peter J. Farrell

unread,
Mar 10, 2010, 1:14:04 PM3/10/10
to mach-ii-for...@googlegroups.com
It's going to be strategyName="" not strategy="" in the <cache> command

And for cache-clear it is going to be strategyNames="' (plural) not strategyName="" since cache-clear can take a list of strategy names.

I would suggest using the DTD for XML document validation since that would immediately show syntax errors like this:

http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/FAQUsingDTD
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/FAQDTDLocation

I think that might help.

.Peter

Derrick Jackson said the following on 10/03/10 12:04:
Hey Peter,

The only module I have in my app is the Dashboard.  The listener is in the base app and is not being used in the Dashboard module.  What I did nfotice when I started using multiple caching strategies is the named strategy I want to clear on occasion never shows any hits in the dashboard.  The default strategy shows hits increasing but not "ConData_Cache" strategy.  I've included the event in question in case I'm doing things in there that I should not be.

Derrick Jackson

unread,
Mar 10, 2010, 1:23:31 PM3/10/10
to mach-ii-for...@googlegroups.com
HA... I was actually typing an email just now stating that I used "strategy" rather than "strategyName" in my listener.  I just changed it to strategyName and tried everything again and my data was still not "refreshed".  Nor did the hits show up in the specified strategy name.  In the clearCacheByAlias method I am doing the following:

<cfif clearCache>
<cfset cacheManager = getAppManager().getCacheManager() />
<cfset cacheManager.clearCacheByStrategyName('ConData_Cache')>
</cfif>

clearCache is "1" so the cache was cleared.  In my logging output I do get the confirmation that the cache was cleared "CacheManager clear cache by strategy name 'ConData_Cache'", but the data on the screen stays the same.  I'm about to walk through my code again to see if there is yet something else I'm missing.

Derrick Jackson

unread,
Mar 10, 2010, 1:32:49 PM3/10/10
to mach-ii-for...@googlegroups.com
Just noticed something.  Per the logging output, the data is in fact being cleared.  Its just not updating in the view itself.  So caching seems to be ok.  I just need to determine why the view is not updating.

Derrick Jackson

unread,
Mar 10, 2010, 1:37:44 PM3/10/10
to mach-ii-for...@googlegroups.com
Even more information.  Sorry for all the emails.

The logging output shows that the resultArg queries returned from the cached listener data are being cleared and updated correctly.  However, on the same page that outputs the dump of the correct logging data a dump of the event args shows that the queries are in fact wrong.  So it seems that there is a disconnect between what is shown in the logging output and what is being put back into the event.

Peter J. Farrell

unread,
Mar 10, 2010, 1:42:42 PM3/10/10
to mach-ii-for...@googlegroups.com
Clearing the cache doesn't clear information in the event object.  So if the data was put into the event before the cache was cleared -- it would the old information.

Derrick Jackson said the following on 10/03/10 12:37:

Derrick Jackson

unread,
Mar 10, 2010, 1:57:20 PM3/10/10
to mach-ii-for...@googlegroups.com
Makes sense... But if the <cache-clear> appears before the creating of the cache as in my event below:


<event-handler event="showApplication" access="public">
   <event-arg name="pageTitle" value="Constituent Data" />
   <execute subroutine="getApplicationData" />
   <event-arg name="applicantStatus" value="1" />
   <cache-clear strategyNames="ConData_Cache" criteria="${event.applicationUUID}" condition="${event.cv}" />
   <cache alias="ConDataSubmitted" strategyName="ConData_Cache" criteria="${event.applicationUUID}" >

       <notify listener="applicantListener" method="getApplicants" resultArg="submittedApplicants" />
   </cache>
   <event-arg name="applicantStatus" value="0" />
   <cache alias="ConDataInProcess" strategyName="ConData_Cache" criteria="${event.applicationUUID}" >

       <notify listener="applicantListener" method="getApplicants" resultArg="inProcessApplicants" />
   </cache>
   <cache alias="constituentDataQuestion" criteria="${event.applicationUUID}">
       <notify listener="questionListener" method="getQuestionsByApplicationUUID" resultArg="questionList"/>
       <notify listener="answerListener" method="getAnswersToQuestions" resultArg="questionAnswerList" />
       <notify listener="answerListener" method="getAnswersByApplicationUUID" resultArg="constituentAnswers"/>
   </cache>
   <view-page name="constituentData.applicantList" contentArg="content" />
   <execute subroutine="mainTemplate" />
</event-handler>

Would the event not be populated with the new data if the cache was cleared?

Peter J. Farrell

unread,
Mar 10, 2010, 2:00:24 PM3/10/10
to mach-ii-for...@googlegroups.com
FYI, I filed a ticket in include the module name of the CacheManager when logging log messages:

http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/ticket/554

This ticket stems from this discussion so in the future it makes it easier to figure out which CacheManager you are talking to when dealing with module inheritance.  This enhancement will be added in the 1.9 branch.

.pjf

Peter J. Farrell said the following on 10/03/10 11:46:

Peter J. Farrell

unread,
Mar 10, 2010, 2:12:31 PM3/10/10
to mach-ii-for...@googlegroups.com
Derrick,

Could you send me your MachII logging output?  Be sure that the logger is listening at the "trace" level (the most low level).  Off list is fine...

Derrick Jackson said the following on 10/03/10 12:57:

Derrick Jackson

unread,
Mar 10, 2010, 2:31:39 PM3/10/10
to mach-ii-for...@googlegroups.com
On its way Peter.

Peter J. Farrell

unread,
Mar 10, 2010, 2:31:43 PM3/10/10
to mach-ii-for...@googlegroups.com
Your cache-clear doesn't need a criteria since criteria only applies when used in conjunction with the "ids" and "aliases" attributes.  Technically, your cache-clear should be clearing the entire cache out.  I'd need to see the logging output to see what is going on.

As an aside...

If you don't assign a cache-handler an "id", Mach-II does it for you (it is a hash of tick count and random numbers).  The "id" value must be unique across your application.  You'll see this in the logging out as "HANDLERID=XXX".

The "alias" attribute allows you group multiple cache-handler ids into a logical group / collection.  Basically, an "alias" is just a pointer to a group of ids.  We keep track of what aliases an "id" belongs to so if you want to clear by alias we just loop over that group of ids.

We use the "id" as part of the key that gets generated before it gets placed in the cache.  The "criteria" attribute is uses to make the cache key unique in conjunction with the "id".  For example:

<!--- Incoming event-arg of productId" --->
<cache id="product">
  <notify listener="product" method="getProductInfo" resultArg="product"/>
</cache>

Since we didn't defined anything else for the cache, the first product to be gotten will be the one cached until it is cleared.  We probably will have many products from this one event-handler, so this is not our intended behavior.  We would need to further customize the cache key:

<!--- Incoming event-arg of productId" --->
<cache id="product" criteria="productId">
  <notify listener="product" method="getProductInfo" resultArg="product"/>
</cache>

This will use the "id" of "product" and the incoming productId to create the cache key.  The cache key in the logging would look something like:

"HANDLERID=PRODUCT&PRODUCTID=123"

So when productId 123 is passed into the system, we ask the cache handler if there is data for the cache key.

HTH,
Peter

Derrick Jackson said the following on 10/03/10 12:57:

Peter J. Farrell

unread,
Mar 10, 2010, 2:43:57 PM3/10/10
to mach-ii-for...@googlegroups.com, Derrick Jackson
Derrick Jackson said the following on 10/03/10 13:31:
> On its way Peter.
Derrick, did you say that the your "ConData_Cache" cache strategy in the
Dashboard says 0 elements in it? Because if that is the case, then
according to your log file -- it's replaying something from the cache.

Somewhere I think things are getting cached in a different handler. Can
you share the entire event-handler again (without modifications) and
your caching configuration xml as well?

.pjf

jlcox

unread,
Mar 10, 2010, 3:03:09 PM3/10/10
to Mach-II for CFML
Just a quick question to avoid being kicked in the head by one of
those butterfly things...are all of your variables properly var-scoped
in your objects?

Derrick Jackson

unread,
Mar 10, 2010, 3:21:32 PM3/10/10
to mach-ii-for...@googlegroups.com
Jlcox,

That was my first thought.  I reviewed them and all looks on the up and up with my variables.


--
Reply all
Reply to author
Forward
0 new messages