Cache-CacheFactory
view release on metacpan or search on metacpan
lib/Cache/CacheFactory.pm view on Meta::CPAN
print "Storage policy '$policy' has driver: ",
Data::Dumper::Dumper( $driver ), "\n";
return $cache->last() if $policy eq 'file';
} );
This will print the policy name and driver object for each storage
policy in turn until it encounters a C<'file'> policy.
=item $cache->foreach_driver( $policytype, $method, @args );
Much like C<foreach_policy()> above, this method iterates over
each policy, this time invoking method C<$method> on the driver
with the arguments specified in C<@args>.
$cache->foreach_driver( 'storage', 'do_something', 'with', 'args' );
will call:
$driver->do_something( 'with', 'args' );
on each storage driver in turn.
The return value of the method called is discarded, if it's
important to you then you should use C<foreach_policy> and
call the method on the driver arg provided, collating the
results however you wish.
=item $cache->last();
Indicates that C<foreach_policy()> or C<foreach_driver> should
exit at the end of the current iteration. C<last()> does B<NOT>
exit your closure for you, if you want it to behave like perl's
C<last> construct you will want to do C<< return $cache->last() >>.
=item $cache->auto_purge( 'set' | 'get' );
Attempts an auto-purge according to the C<auto_purge_on_set> and
C<auto_purge_on_get> settings and the C<< $cache->get_last_auto_purge() >>
value.
=item $cache->error( $error_message );
Raise a fatal error with message given by C<$error_message>.
=item $cache->warning( $warning_message );
Raise a warning with message given by C<$warning_message>.
=back
=head1 KNOWN ISSUES AND BUGS
=over
=item Pruning and validity policies are per-cache rather than per-storage
Pruning and validity policies are set on a per-cache basis rather than
on a per-storage-policy basis, this makes multiple storage policies
largely pointless for most purposes where you'd find it useful.
If you wanted the cache to transparently use a small fast memory cache
first and fall back to a larger slower file cache as backup: you can't
do it, because the size pruning policy would be the same for both storage
policies.
About the only current use of multiple storage policies is to have a
memory cache and a file cache so that processes that haven't pulled
a copy into their memory cache yet will retreive it from the copy
another process has placed in the file cache. This might be slightly
more useful than a shared memory cache since the on-file cache will
persist even if there's no running processes unlike the shared memory
cache.
Per-storage pruning and validity settings may make it into a future
version if they prove useful and won't over-complicate matters - for
now it's best to create a wrapper module that internally creates the
caches seperately but presents the Cache::Cache API externally.
=item Add/replace aren't atomic
The C<< $cache->add/replace() >> methods aren't atomic, this mostly
defeats their purpose in a shared-cache situation. This could be
considered a bug.
=item Aren't there a million Cache::Cache replacements already?
At the time I started writing L<Cache::CacheFactory> I'd been trying
to find a caching solution that had the combination of features I
needed, I had no luck in finding one.
Since then I've found a couple of other similar modules, and more
have been written and released, you may or may not find them suiting
your needs more closely, so I suggest taking a good look:
L<CHI> - this module appears to have much the same motivation and
strategy as L<Cache::CacheFactory> in terms of storage policies,
however, from what I can gather, it doesn't appear to split
validity/pruning policies into seperate and/or combinable modules.
L<Cache> - not sure how I missed this one when I was researching,
it's a mature module that gives you flexibile validity/pruning
policies but doesn't have such a wide range of storage policies
available.
Please note that these descriptions are from my own imperfect
understanding of the modules concerned, by no means take them
as an authorative description of their functionality. Please
feel free to contact me if I've included any inaccuracies. :)
=back
=head1 SEE ALSO
L<Cache::Cache>, L<Cache::CacheFactory::Object>,
L<Cache::CacheFactory::Expiry::Base>,
L<Cache::CacheFactory::Expiry::Time>,
L<Cache::CacheFactory::Expiry::Size>,
L<Cache::CacheFactory::Expiry::LastModified>,
L<Cache::FastMemoryCache>
=head1 SUPPORT
( run in 0.992 second using v1.01-cache-2.11-cpan-e1769b4cff6 )