I've developed a web application that uses CHI to cache data in
memcached and local file caches. When developing I often like to
disable caching and I do this by using CHI::Driver::Null. But, I've
found that this is too global and doesn't actually fit my needs. I
need a way to tell CHI to stop caching within a smaller scope. Being
able to do something like:
$chi->disable();
$chi->enable();
Anyone have any thoughts? I was thinking about making a Moose Role
the overrides fetch and returns undef, when caching is turned off, but
that only works for the first cache level, not any l1_caches/
sub_caches. I'd have to apply this role to all the caches for it to
work, and I'd have to have some way for the children caches to walk
their way up to the main parent cache to find out whether caching is
disabled. Sound funky and painful, but doable. It feels like a hack
too. Anyone have a better way of doing this?
Thanks much,
Aran
Are you wanting to disable caching temporarily for a particular cache
object, or for all cache objects created anywhere in your application?
e.g. in your example is $chi a cache object returned by CHI->new?
Jon
I wonder - another solution might be to create a new driver that is a
gate-keeper of sorts. It is aware of whether caching is enabled or
not, if its not it never passes control to subcaches, otherwise it
always passes control on to the subcaches. From what I remember of
the driver architecture this would be pretty doable.
Aran
sub new {
my $class = shift;
if ($CACHING_DISABLED) {
return $class->SUPER::new(driver => 'Null');
}
else {
return $class->SUPER::new(@_);
}
}
The new() will be called for main caches and subcaches, so it should
catch everything. Or, you could apply your role here.
Creating a private CHI subclass is a good practice in general because
it gives you the flexibility to do these sorts of things. It's
something I want to start encouraging in the documentation ala Rose::DB.
Jon
> --
>
> You received this message because you are subscribed to the Google
> Groups "Perl-Cache Discuss" group.
> To post to this group, send email to perl-cach...@googlegroups.com
> .
> To unsubscribe from this group, send email to perl-cache-disc...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/perl-cache-discuss?hl=en
> .
>
>