Sorry I guess I got distracted and copy/pasted from the wrong line.
The listener is defined in the base module, the cache alias I am
trying to clear is in a separate module. I would like to be able to
clear caches by alias regardless of which module they are in.

Here's my entire listener:
<cffunction name="clearCacheByAlias" access="public"
returntype="string" output="false">
                <cfargument name="event" type="MachII.framework.Event"
required="true">
                <cfset var cacheAlias = event.getArg('alias')/>
                <cfset var module = event.getArg('module')/>
                <cfset var cacheManager = ""/>

                <!--- Get the right CacheManager context based on the module 
--->
                <cfif Len(module)>
                        <cfset cacheManager =
getAppManager().getModuleManager().getModule(module).getAppManager().getCacheManager()
 /
>
                <cfelse>
                        <cfset cacheManager = getAppManager().getCacheManager() 
/>
                </cfif>

                <cfset
cacheManager.clearCachesByAlias(cacheAlias,arguments.event,'')/>

        </cffunction>

I use this url:
/index.cfm?event=clear-module-cache&module=homepage&alias=homePage

clear-module-cache hits a listener and runs this to set the context of
the cache clear to the module the alias is in:

               <cfset var module = event.getArg('module')/>
               <cfset announceEventInModule(module,"clear-alias-
cache",event.getArgs())>

the event "clear-alias-cache" hits the function I pasted in at the top
that runs
<cfset cacheManager.clearCachesByAlias(cacheAlias,arguments.event,'')/
>

Here's the log output of this sequence:

MachII.framework.RequestHandler
Event-handler 'clear-module-cache' in module '' beginning execution.
lib.components.listeners.CacheSupportListener
Listener 'CacheSupportListener' invoking method 'clearCacheInModule'.
MachII.framework.EventContext
Announcing event 'clear-alias-cache' in module 'homepage'.
MachII.framework.RequestHandler
Event-handler 'clear-module-cache' in module '' has ended.
MachII.framework.RequestHandler
Event-handler 'clear-alias-cache' in module 'homepage' beginning
execution.
lib.components.listeners.CacheSupportListener
Listener 'CacheSupportListener' invoking method 'clearCacheByAlias'.
MachII.framework.RequestHandler
Event-handler 'clear-alias-cache' in module 'homepage' has ended.
MachII.framework.RequestHandler
info
End processing request.

If I comment out the call to my listener in event clear-alias-cache
and do this instead:

               <event-handler event="clear-alias-cache">
                       <!--<notify listener="cacheSupport"
method="clearCacheByAlias"/>  --


                       <cache-clear aliases="homepage"/>
               </event-handler>

It works, and I get his log output:

MachII.framework.RequestHandler
Event-handler 'clear-module-cache' in module '' beginning execution.
lib.components.listeners.CacheSupportListener
Listener 'CacheSupportListener' invoking method 'clearCacheInModule'.
MachII.framework.EventContext
Announcing event 'clear-alias-cache' in module 'homepage'.
MachII.framework.RequestHandler
Event-handler 'clear-module-cache' in module '' has ended.
MachII.framework.RequestHandler
Event-handler 'clear-alias-cache' in module 'homepage' beginning
execution.
MachII.framework.commands.CacheClearCommand
Clearing cache by aliases 'homepage' (no condition to evaluate).
MachII.framework.CacheHandler
Cache-handler clearing all data from cache that start with id
'5DA2A7D7919995E4D496265B2569374C'
MachII.framework.CacheHandler
Cache-handler clearing all data from cache that start with id
'AD4C5F9CBA54D3FD1BC02836217DDCE3'
MachII.framework.CacheHandler
Cache-handler clearing all data from cache that start with id
'3057ED66888C4298EAA0CF98DE77790D'
MachII.framework.CacheHandler
Cache-handler clearing all data from cache that start with id
'31215D8BC98E58738D5D9D1296DCF58F'
MachII.framework.RequestHandler
Event-handler 'clear-alias-cache' in module 'homepage' has ended.
MachII.framework.RequestHandler
End processing request.

One thing that is particularly confusing is why I'm not getting the
output of the log.trace statement in the clearCachesByAlias function
when I call it from the listener (Clearing cache by aliases
'homepage' (no condition to evaluate)).

On Feb 11, 7:03 pm, "Peter J. Farrell" <[email protected]> wrote:
> Could you share more of your code that you are using in your listener?  
> Are you using any modules?  There is a CacheManager for the base
> application and one for each module.
>
> I guess I'm confused by this piece of code that you shared:
>
> <cfif StructKeyExists(variables.handlersByAliases, 
> getKeyHash(arguments.alias))>
>
> To clear a cache from a listener, the code would be something like:
>
> <cfset getAppManager().getCacheManager().clearCachesByAlias("alias",
> arguments.event, "ListOfCriteria") />
>
> Or in your case:
>
> <cfset
> getAppManager().getCacheManager().clearCachesByAlias(arguments.event.getArg("alias"),
> arguments.event, "") />
>
> As for the CacheClearCommand.cfc, it is not doing anything special for you:
>
> http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/browser/framework/1-...
>
> Best,
> .Peter
>
> Jeremy.Shearer said the following on 11/02/10 10:59:
>
> > Currently I have an event in a module that clears the cache for a
> > specific alias:
>
> > <cache-clear aliases="homePage"/>
>
> > I can see in the mach-ii logging where it hits the
> > CacheManager.clearCachesByAlias trace statements and clears the cached
> > items in the homePage alias.
>
> > I would like to be able to pass in the alias in an event arg, but I
> > can't just do<cache-clear aliases="${event.alias}"/>
>
> > So I moved it into a listener,
>
> > <cfif StructKeyExists(variables.handlersByAliases,
> > getKeyHash(arguments.alias))>
>
> > I added some of my own trace statements into the clearCachesByAlias
> > function and I can see them in the output, but this line returns false
> > and so nothing gets cleared from the c
> > ache:
> > <cfif StructKeyExists(variables.handlersByAliases,
> > getKeyHash(arguments.alias))>
>
> > Is there something special that the CacheClearCommand.cfc sets up that
> > I'm not getting by calling clearCachesByAlias() directly from my
> > listener?

-- 
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
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/

Reply via email to