[Catalyst] clear() method for Catalyst::Plugin::Cache?

Larry Leszczynski larryl at emailplus.org
Sat Mar 7 01:34:37 GMT 2009


On Fri, 06 Mar 2009 20:11 -0500, "Jason Kohles" <email at jasonkohles.com>
wrote:
> On Mar 6, 2009, at 7:42 PM, Larry Leszczynski wrote:
> 
> > Does it make sense to add a clear() method to Catalyst::Plugin::Cache,
> > in addition to the existing get(), set() and remove()?  It seems  
> > like a
> > common action for cache manipulation.
> >
> > Any of the various Cache::Cache-based backend flavors should be able  
> > to
> > support it out of the box.  For specific backends that use a different
> > method name to accomplish clearing the cache (e.g.
> > Cache::Memcached::libmemcached::flush_all), would need to come up  
> > with a
> > way to map method names - maybe a config option?:
> >
> >    __PACKAGE__->config->{'Plugin::Cache'}{backend} = {
> >        class   => "Cache::Memcached::libmemcached",
> >        method_map => {
> >                       clear => 'flush_all',
> >                      },
> >        servers => ['127.0.0.1:11211'],
> >        debug   => 2,
> >    };
> >
> I think this code is a great example of why this is a bad idea as a  
> general practice.  If the only thing you are using memcached for is  
> session cache, then mapping clear to flush_all has the desired effect,  
> but if you are using memcached for more than just session caches, then  
> flush_all could be a very bad idea.

Actually, not using it for session caching at all, just other various
bits and pieces of data.  But I see your point about the danger of
clearing/flushing more than you might expect.  Regardless of cache
flavor, you could set up separate backend instances for different pools
of data (via e.g. different cache_roots for Cache::FileCache or
different server instances for Cache::Memcached::libmemcached) and make
sure you only clear() the intended backend.


Larry



More information about the Catalyst mailing list