1Cache::BaseCache(3)   User Contributed Perl Documentation  Cache::BaseCache(3)
2
3
4

NAME

6       Cache::BaseCache -- abstract cache base class
7

DESCRIPTION

9       BaseCache provides functionality common to all instances of a cache.
10       It differes from the CacheUtils package insofar as it is designed to be
11       used as superclass for cache implementations.
12

SYNOPSIS

14       Cache::BaseCache is to be used as a superclass for cache implementa‐
15       tions.  The most effective way to use BaseCache is to use the protected
16       _set_backend method, which will be used to retrieve the persistance
17       mechanism.  The subclass can then inherit the BaseCache's implentation
18       of get, set, etc.  However, due to the difficulty inheriting static
19       methods in Perl, the subclass will likely need to explicitly implement
20       Clear, Purge, and Size.  Also, a factory pattern should be used to
21       invoke the _complete_initialization routine after the object is con‐
22       structed.
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         sub Clear
51         {
52           foreach my $namespace ( _Namespaces( ) )
53           {
54             _Get_Backend( )->delete_namespace( $namespace );
55           }
56         }
57
58         sub Purge
59         {
60           foreach my $namespace ( _Namespaces( ) )
61           {
62             _Get_Cache( $namespace )->purge( );
63           }
64         }
65
66         sub Size
67         {
68           my $size = 0;
69
70           foreach my $namespace ( _Namespaces( ) )
71           {
72             $size += _Get_Cache( $namespace )->size( );
73           }
74
75           return $size;
76         }
77

SEE ALSO

79       Cache::Cache, Cache::FileCache, Cache::MemoryCache
80

AUTHOR

82       Original author: DeWitt Clinton <dewitt@unto.net>
83
84       Last author:     $Author: dclinton $
85
86       Copyright (C) 2001-2003 DeWitt Clinton
87
88
89
90perl v5.8.8                       2003-04-15               Cache::BaseCache(3)
Impressum