Cache::BaseCache(3pm)
๐ Cache::BaseCache โ the manual, but make it cute ๐
okay bestie, welcome to Cache::BaseCache(3pm) from the User Contributed Perl Documentation ๐
this is the โจ abstract cache base class โจ and she's giving blueprint energy, not do-the-thing energy. sit down, hydrate, let's go ๐
๐ธ NAME ๐ธ
Cache::BaseCache โ abstract cache base class. yes that's literally it, she's abstract, she's a base, she's a class. icon behavior ๐
โจ DESCRIPTION โจ
so <pink>BaseCache</pink> brings the functionality that every single instance of a cache has in common. all of them. every last one ๐ซถ
the way it differs from the CacheUtils package is โ and this is the key part, iykyk โ it's designed to be used as a superclass for cache implementations. like, that's her whole purpose. she's the mom of the cache family, and she's not doing the caching herself, she's just handing down the genetics ๐งฌ๐
๐ SYNOPSIS ๐
Cache::BaseCache is meant to be used as a superclass for cache implementations. periodt.
the most effective way to use BaseCache is to use the protected _set_backend method โ that's the one that gets used to retrieve the persistence mechanism. once you've done that, your subclass can then inherit BaseCache's implementation of get, set, etc. slay, free real estate โจ
but โ and listen, this is the plot twist ๐ญ โ because inheriting static methods in Perl is genuinely difficult, your subclass will likely need to explicitly implement Clear, Purge, and Size. no shortcuts there, bestie, you're writing those yourself.
also, a factory pattern should be used to invoke the _complete_initialization routine after the object is constructed. that's the move. that's the ritual. do not skip the ritual ๐ฎ
here's the whole vibe in code, verbatim, because I would never dream of touching a single character:
package Cache::MyCache;
use vars qw( @ISA );
use Cache::BaseCache;
use Cache::MyBackend;
@ISA = qw( Cache::BaseCache );
sub new
{
my ( $self ) = _new( @_ );
$self->_complete_initialization( );
return $self;
}
sub _new
{
my ( $proto, $p_options_hash_ref ) = @_;
my $class = ref( $proto ) || $proto;
my $self = $class->SUPER::_new( $p_options_hash_ref );
$self->_set_backend( new Cache::MyBackend( ) );
return $self;
}
sub Clear
{
foreach my $namespace ( _Namespaces( ) )
{
_Get_Backend( )->delete_namespace( $namespace );
}
}
sub Purge
{
foreach my $namespace ( _Namespaces( ) )
{
_Get_Cache( $namespace )->purge( );
}
}
sub Size
{
my $size = 0;
foreach my $namespace ( _Namespaces( ) )
{
$size += _Get_Cache( $namespace )->size( );
}
return $size;
}
see how Clear, Purge, and Size are all just right there, hand-written by the subclass? yeah. that's the static-method tax. she takes her cut ๐
๐ SEE ALSO ๐
go read these next, bestie, they're the rest of the friend group:
Cache::CacheCache::FileCacheCache::MemoryCache
๐ซถ AUTHOR ๐ซถ
- Original author: DeWitt Clinton
<dewitt@unto.net> - Last author:
$Author: dclinton $ - Copyright (C) 2001-2003 DeWitt Clinton
no cap, that's the whole page. every method, every@ISA, everyforeach, all preserved exactly. I would never gatekeep a_set_backendfrom you ๐
and that's a wrap, my love โ this little masterpiece came to you courtesy of perl v5.34.0, dated 2022-06-30, and it's filed under Cache::BaseCache(3pm). go forth and subclass responsibly, mwah ๐๐โจ
๐ฆ where this page comes from
- debian bookworm: libcache-cache-perl 1.08-3 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- debian trixie: libcache-cache-perl 1.08-3 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu noble: libcache-cache-perl 1.08-3 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu resolute: libcache-cache-perl 1.08-3 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu stonking: libcache-cache-perl 1.08-3 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms