Accessing Cache from a Listener

1 view
Skip to first unread message

jason.york

unread,
Dec 17, 2009, 8:44:40 AM12/17/09
to Mach-II for CFML
I wanted to get your opinion to see if this would be a "recommended"
way to access the Mach-ii cache. I want to be able to put and get
items from the cache from my listener. I am able to do so through a
call such as:
getAppManager().getCacheManager().getCacheStrategyManager
().getCacheStrategyByName("mycache").get(key)
and
getAppManager().getCacheManager().getCacheStrategyManager
().getCacheStrategyByName("mycache").put(key, data)

Is this something you would discourage?

Thanks,
-- Jason


Peter J. Farrell

unread,
Dec 17, 2009, 12:28:39 PM12/17/09
to mach-ii-for...@googlegroups.com
Yes, I think that is a reasonable (and really the only approach).  You might save yourself some typing and few CPU cycles by stashing a reference to the cache in your configure() method

<cffunction name="configure">
    <cfset variables.myCache = getAppManager().getCacheManager().getCacheStrategyManager().getCacheStrategyByName("mycache") />
</cffunction>

Then just reference <cfset variables.myCache.put/get() /> where necessary.  Remember to construct a unique key.

Probably not a lot of people in Mach-II have done this yet (I've used the caching package for non-Mach-II projects a bit).  If you think have any ideas that might help integration for places like this (listeners, or non-Mach-II applications) that would make working with the caching package easier -- please feel free to bring it up on the list.

Best,
.Peter

P.s.  There is a page on the wik on using the caching package outside of Mach-II application -- which would apply here.  Feel free to expand:

https://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/UsingCachingOutsideOfMachII

It doesn't show using the CacheStrategyManager which was designed to be used independently of Mach-II MVC as well.

jason.york said the following on 12/17/2009 07:44 AM:
--

The Harmonious Programmer

Peter J. Farrell
Email: pe...@mach-ii.com | pjf@maestropublishing
Blog: The Harmonious Programmer
Twitter/Identi.ca: @maestrofjp

Kurt Wiersma

unread,
Dec 17, 2009, 4:40:09 PM12/17/09
to mach-ii-for...@googlegroups.com
Most of the time I found myself using the caching commands in the Mach II XML file or using them inside my service layer but I could see how you might want to use it inside your listeners.

--Kurt

--
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/

TheHarmoniousProgrammer.1.gif

Brian Klaas

unread,
Dec 18, 2009, 10:02:29 AM12/18/09
to Mach-II for CFML
I added a small block to the wiki page about accessing a cache from a
listener. I can definitely see how this would be useful.

On Dec 17, 12:28 pm, "Peter J. Farrell" <pe...@mach-ii.com> wrote:
> Yes, I think that is a reasonable (and really the only approach).  You
> might save yourself some typing and few CPU cycles by stashing a
> reference to the cache in your configure() method
>
> <cffunction name="configure">
>     <cfset variables.myCache =

> getAppManager().getCacheManager().getCacheStrategyManager().getCacheStrateg yByName("mycache")


> />
> </cffunction>
>
> Then just reference <cfset variables.myCache.put/get() /> where
> necessary.  Remember to construct a unique key.
>
> Probably not a lot of people in Mach-II have done this yet (I've used
> the caching package for non-Mach-II projects a bit).  If you think have
> any ideas that might help integration for places like this (listeners,
> or non-Mach-II applications) that would make working with the caching
> package easier -- please feel free to bring it up on the list.
>
> Best,
> .Peter
>
> P.s.  There is a page on the wik on using the caching package outside of
> Mach-II application -- which would apply here.  Feel free to expand:
>

> https://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/UsingCachingOu...


>
> It doesn't show using the CacheStrategyManager which was designed to be
> used independently of Mach-II MVC as well.
>
> jason.york said the following on 12/17/2009 07:44 AM:
>
>
>
>
>
> > I wanted to get your opinion to see if this would be a "recommended"
> > way to access the Mach-ii cache.  I want to be able to put and get
> > items from the cache from my listener.  I am able to do so through a
> > call such as:
> > getAppManager().getCacheManager().getCacheStrategyManager
> > ().getCacheStrategyByName("mycache").get(key)
> > and
> > getAppManager().getCacheManager().getCacheStrategyManager
> > ().getCacheStrategyByName("mycache").put(key, data)
>
> > Is this something you would discourage?
>
> > Thanks,
> >   -- Jason
>
> --
>

> The Harmonious Programmer
> <http://feeds.feedburner.com/%7Er/TheHarmoniousProgrammer/%7E6/1>
>
> *Peter J. Farrell*
> Email: pe...@mach-ii.com | pjf@maestropublishing
> Blog: The Harmonious Programmer <http://blog.maestropublishing.com>
> Twitter/Identi.ca: @maestrofjp

jason.york

unread,
Dec 21, 2009, 2:08:22 PM12/21/09
to Mach-II for CFML
I added on a little to Brian's wiki entry with an example that shows
how to check to see if caching is enabled.
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/IntroToCaching#AccessingtheCachefromaMach-IIListener

I guess this really brings up the question if 'put' should put the
entry in the cache if it's disabled... or should it just be left up to
the specific implementation? What should the expected behavior be?

-- Jason

Peter J. Farrell

unread,
Dec 21, 2009, 3:23:05 PM12/21/09
to mach-ii-for...@googlegroups.com
Enable/disable of caching is up to the implementation. Basically it's a suggestion not a directive. If you are doing low level calls like get/put you'll need to check if caching is enabled. This is how most caching systems work.

.Pjf
Reply all
Reply to author
Forward
0 new messages