Hi Peter Thanks for that excellent explanation, it's very helpful.
Your right in saying that I assumed the unique key would 'navigation' and hence could not extract anything. However, I'm a little lost as to how I get that key if Mach-ii computes it? Or wound something like this be much easier and straight forward to do in the listener, as I have that working just fine at the moment. Thanks On Oct 14, 6:43 pm, "Peter J. Farrell" <[email protected]> wrote: > jbuda said the following on 10/14/2010 06:01 AM:> <cache > aliases="full-navigation" strategyName="full_navigation" id="navigation"> > > <notify listener="SiteMapListener" method="fullNavigation" > > returnArg="navigation" /> > > </cache> > > I think the issue is that you're assuming that the cache key generated > by Mach-II is "navigation" and this isn't the case. Actually, because > of the complexity of offering caching in controller layer and in the > XML, the keys are computed. > > Cache handlers without the "id" attribute use a generated number so if > you need to access them you at least need to set an "id". Also this the > cache key can have other data mixed into it when you start using the > criteria attribute. > > If you turn on Mach-II logging, you can see the keys being used -- you > shouldn't base this off the logging output, but I'm mentioning it so you > can see what's going on. Here's a snippet: > > MachII.framework.CacheHandler > > debug > > Created cache with key 'HANDLERID=263D72D55687C48BBF4428CAECA5E6D2'. > > 0 > > MachII.framework.CacheHandler > > debug > > Cached data contained key names of 'count,layout.subNavTabs,layout.content'. > > 1 > > MachII.framework.CacheHandler > > trace > > Cached 10 HTML head elements. > > 0 > > MachII.framework.CacheHandler > > trace > > Cached 0 HTML body elements. > > 1 > > MachII.framework.CacheHandler > > trace > > Cached 0 HTTP headers. > > 0 > > > <cfdump > > var="#getAppManager().getCacheManager().getCacheStrategyManager().getCacheS > > trategyByName("full_navigation").get("navigation")#"> > > At this point, you need the cache key to pass to the caching strategy, > but you only have the cache handler id. Anything cached from a <cache> > handler use a key format of this: > > HANDLERID={cacheHandlerId}&PRODUCTID={valueOfProductId} > > The HANDLERID is the "id" of the <cache> handler or if there is no "id" > then it's auto-generated. It is followed by any criteria you have > defined in the <cache> in uppercase and sorted alphnum ASC. > > So in this case you example should work using a key because you are not > using any criteria: > > <cfdump > var="#getAppManager().getCacheManager().getCacheStrategyManager().getCacheS > trategyByName("full_navigation").get("HANDLERID=navigation")#"> > > The issue you will run into is "what if the requested key isn't > defined?" This is taken care for you in the XML because the required > commands are nested in the <cache> handler, but when you are accessing > that data outside of XML syntax -- the data could not be in the cache > yet. I'd say for situations where you want to take advantage of using > cached data from the cache API like you want to -- I'd just do it > manually in your listener. That way you can handle when you don't have > cached data: > > <cfset var data = > getAppManager().getCacheManager().getCacheStrategyManager().getCacheStrateg > yByName("full_navigation").get("navigation") > /> > > <!--- If nothing is in the cache, then data won't be available because > the strategy returns NULL ---> > <cfif NOT IsDefined("data")> > .... run code to get the data ... > <cfset data = getSomeService().someMethod() /> > <cfset > getAppManager().getCacheManager().getCacheStrategyManager().getCacheStrateg > yByName("full_navigation").put("navigation", > data) /> > </cfif> > > <cfreturn data /> > > HTH, > .Peter -- 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 ***New URLs as of April 29th, 2010*** SVN: http://svn.mach-ii.com/machii/ Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/
