Cache::SizeAwareCache β extends the Cache interface.
| Use Case | Command | Description |
|---|---|---|
| π¦ Create a size-aware cache module | use parent qw(Cache::SizeAwareCache); | Subclass the interface to build your own cache |
| π Set maximum cache size | $cache->set_max_size(1024); | Enforce a hard byte limit (expensive on every set) |
| π§Ή Oneβtime size reduction | $cache->limit_size(512); | Shrink cache to β€ $new_size bytes now |
| β»οΈ Periodic size maintenance | $cache->limit_size(8192); | Recommended alternative to max_size β call in a cron/scheduler |
| β Disable size limit | $cache->set_max_size($NO_MAX_SIZE); | Default β no automatic size enforcement |
The SizeAwareCache interface is implemented by classes that support all of the Cache::Cache interface in addition to the limit_size and max_size features of a size aware cache.
The default cache size limiting algorithm works by removing cache objects in the following order until the desired limit is reached:
use Cache::SizeAwareCache;
use vars qw( @ISA );
@ISA = qw( Cache::SizeAwareCache );
Please see Cache::Cache for standard constants
$NO_MAX_SIZE β The cache has no size restrictionsPlease see Cache::Cache for the standard methods
limit_size( $new_size ) β Attempt to resize the cache such that the total disk usage is under the $new_size parameter. $new_size represents the size (in bytes) that the cache should be limited to. Note that this is only a oneβtime adjustment. To maintain the cache size, consider using the max_size option, although it is considered very expensive, and can often be better achieved by periodically calling limit_size.Please see Cache::Cache for the standard options
max_size β Sets the max_size property (size in bytes), which is described in detail below. Defaults to $NO_MAX_SIZE.Please see Cache::Cache for standard properties
(get|set)_max_size β If this property is set, then the cache will try not to exceed the max size value (in bytes) specified. NOTE: This causes the size of the cache to be checked on every set, and can be considered very expensive in some implementations. A good alternative approach is to leave max_size as $NO_MAX_SIZE and to periodically limit the size of the cache by calling the limit_size( $size ) method.Original author: DeWitt Clinton <dewitt AT unto.net>
Last author: $Author: dclinton $
Copyright Β© 2001β2003 DeWitt Clinton
Generated by phpman v4.9.25-3-gdbaf087 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-06 21:36 @216.73.217.93
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format