1Cache::BaseCache(3) User Contributed Perl Documentation Cache::BaseCache(3)
2
3
4
6 Cache::BaseCache -- abstract cache base class
7
9 BaseCache provides functionality common to all instances of a cache.
10 It differs from the CacheUtils package insofar as it is designed to be
11 used as superclass for cache implementations.
12
14 Cache::BaseCache is to be used as a superclass for cache
15 implementations. The most effective way to use BaseCache is to use the
16 protected _set_backend method, which will be used to retrieve the
17 persistence mechanism. The subclass can then inherit the BaseCache's
18 implementation of get, set, etc. However, due to the difficulty
19 inheriting static methods in Perl, the subclass will likely need to
20 explicitly implement Clear, Purge, and Size. Also, a factory pattern
21 should be used to invoke the _complete_initialization routine after the
22 object is constructed.
23
24 package Cache::MyCache;
25
26 use vars qw( @ISA );
27 use Cache::BaseCache;
28 use Cache::MyBackend;
29
30 @ISA = qw( Cache::BaseCache );
31
32 sub new
33 {
34 my ( $self ) = _new( @_ );
35
36 $self->_complete_initialization( );
37
38 return $self;
39 }
40
41 sub _new
42 {
43 my ( $proto, $p_options_hash_ref ) = @_;
44 my $class = ref( $proto ) || $proto;
45 my $self = $class->SUPER::_new( $p_options_hash_ref );
46 $self->_set_backend( new Cache::MyBackend( ) );
47 return $self;
48 }
49
50
51 sub Clear
52 {
53 foreach my $namespace ( _Namespaces( ) )
54 {
55 _Get_Backend( )->delete_namespace( $namespace );
56 }
57 }
58
59
60 sub Purge
61 {
62 foreach my $namespace ( _Namespaces( ) )
63 {
64 _Get_Cache( $namespace )->purge( );
65 }
66 }
67
68
69 sub Size
70 {
71 my $size = 0;
72
73 foreach my $namespace ( _Namespaces( ) )
74 {
75 $size += _Get_Cache( $namespace )->size( );
76 }
77
78 return $size;
79 }
80
82 Cache::Cache, Cache::FileCache, Cache::MemoryCache
83
85 Original author: DeWitt Clinton <dewitt@unto.net>
86
87 Last author: $Author: dclinton $
88
89 Copyright (C) 2001-2003 DeWitt Clinton
90
91
92
93perl v5.32.1 2021-01-26 Cache::BaseCache(3)