NAME
Cache::CacheFactory::Expiry::Size - size-based expiry policy for Cache::CacheFactory.
DESCRIPTION
Cache::CacheFactory::Expiry::Size is a size-based expiry (pruning and validity) policy for Cache::CacheFactory.
It provides similar functionality and backwards-compatibility with the max_size
option of Cache::SizeAwareFileCache and variants.
It's highly recommended that you DO NOT use this policy as a validity policy, as calculating the size of the contents of the cache on each read can be quite expensive, and it's semantically ambiguous as to just what behaviour is intended by it anyway.
Note that in its current implementation Cache::CacheFactory::Expiry::Size is "working but highly inefficient" when it comes to purging. It is provided mostly for completeness while a revised version is being worked on.
SIZE SPECIFICATIONS
Currently all size values must be specified as numbers and will be interpreted as bytes. Future versions reserve the right to supply the size as a string '10 M' for ease of use, but this is not currently implemented.
STARTUP OPTIONS
The following startup options may be supplied to Cache::CacheFactory::Expiry::Size, see the Cache::CacheFactory documentation for how to pass options to a policy.
- max_size => $size
-
This sets the maximum size that the cache strives to keep under, any items that take the cache over this size will be pruned (for a pruning policy) at the next
$cache->purge()
.See the "SIZE SPECIFICATIONS" section above for details on what values you can pass in as
$size
.Note that by default pruning policies are not immediately enforced, they are only applied when a
$cache->purge()
occurs. This means that it is possible (likely even) for the size of the cache to exceedmax_size
at least on a temporary basis. When the next$cache->purge()
occurs, the cache will be reduced back down belowmax_size
.If you make use of the
auto_purge_on_set
option to Cache::CacheFactory, you'll cause a$cache->purge()
on a regular basis depending on the value ofauto_purge_interval
.However, even with the most aggressive values of
auto_purge_interval
there will still be a best-case scenario of the cache entry being written to the cache, taking it overmax_size
, and the purge then reducing the cache belowmax_size
. This is essentially unavoidable since it's impossible to know the size an entry will take in the cache until it has been written.
STORE OPTIONS
There are no per-key options for this policy.
SEE ALSO
Cache::CacheFactory, Cache::Cache, Cache::SizeAwareFileCache, Cache::SizeAwareCache, Cache::CacheFactory::Object, Cache::CacheFactory::Expiry::Base
AUTHORS
Original author: Sam Graham <libcache-cachefactory-perl BLAHBLAH illusori.co.uk>
Last author: $Author: illusori $
COPYRIGHT
Copyright 2008 Sam Graham.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.