File Coverage

blib/lib/Cache/SizeAwareCache.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             ######################################################################
2             # $Id: SizeAwareCache.pm,v 1.11 2003/04/15 14:46:23 dclinton Exp $
3             # Copyright (C) 2001-2003 DeWitt Clinton All Rights Reserved
4             #
5             # Software distributed under the License is distributed on an "AS
6             # IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or
7             # implied. See the License for the specific language governing
8             # rights and limitations under the License.
9             ######################################################################
10              
11              
12             package Cache::SizeAwareCache;
13              
14              
15 2     2   30 use strict;
  2         37  
  2         30  
16 2     2   29 use Cache::Cache;
  2         18  
  2         34  
17 2     2   28 use vars qw( @ISA @EXPORT_OK $EXPIRES_NOW $EXPIRES_NEVER $NO_MAX_SIZE );
  2         18  
  2         25  
18 2     2   29 use Exporter;
  2         51  
  2         27  
19              
20             @ISA = qw( Cache::Cache Exporter );
21              
22             @EXPORT_OK = qw( $EXPIRES_NOW $EXPIRES_NEVER $NO_MAX_SIZE );
23              
24             $EXPIRES_NOW = $Cache::Cache::EXPIRES_NOW;
25             $EXPIRES_NEVER = $Cache::Cache::EXPIRES_NEVER;
26             $NO_MAX_SIZE = -1;
27              
28              
29             sub limit_size;
30              
31             sub get_max_size;
32              
33             sub set_max_size;
34              
35              
36             1;
37              
38              
39             __END__
40            
41            
42             =pod
43            
44             =head1 NAME
45            
46             Cache::SizeAwareCache -- extends the Cache interface.
47            
48             =head1 DESCRIPTION
49            
50             The SizeAwareCache interface is implemented by classes that support
51             all of the Cache::Cache interface in addition to the limit_size and
52             max_size features of a size aware cache.
53            
54             The default cache size limiting algorithm works by removing cache
55             objects in the following order until the desired limit is reached:
56            
57             1) objects that have expired
58             2) objects that are least recently accessed
59             3) objects that that expire next
60            
61             =head1 SYNOPSIS
62            
63             use Cache::SizeAwareCache;
64             use vars qw( @ISA );
65            
66             @ISA = qw( Cache::SizeAwareCache );
67            
68             =head1 CONSTANTS
69            
70             Please see Cache::Cache for standard constants
71            
72             =over
73            
74             =item I<$NO_MAX_SIZE>
75            
76             The cache has no size restrictions
77            
78             =back
79            
80             =head1 METHODS
81            
82             Please see Cache::Cache for the standard methods
83            
84             =over
85            
86             =item B<limit_size( $new_size )>
87            
88             Attempt to resize the cache such that the total disk usage is under
89             the I<$new_size> parameter. I<$new_size> represents t size (in bytes)
90             that the cache should be limited to. Note that this is only a one
91             time adjustment. To maintain the cache size, consider using the
92             I<max_size> option, although it is considered very expensive, and can
93             often be better achieved by peridocally calling I<limit_size>.
94            
95             =back
96            
97             =head1 OPTIONS
98            
99             Please see Cache::Cache for the standard options
100            
101             =over
102            
103             =item I<max_size>
104            
105             Sets the max_size property (size in bytes), which is described in
106             detail below. Defaults to I<$NO_MAX_SIZE>.
107            
108             =back
109            
110             =head1 PROPERTIES
111            
112             Please see Cache::Cache for standard properties
113            
114             =over
115            
116             =item B<(get|set)_max_size>
117            
118             If this property is set, then the cache will try not to exceed the max
119             size value (in bytes) specified. NOTE: This causes the size of the
120             cache to be checked on every set, and can be considered *very*
121             expensive in some implementations. A good alternative approach is
122             leave max_size as $NO_MAX_SIZE and to periodically limit the size of
123             the cache by calling the limit_size( $size ) method.
124            
125             =back
126            
127             =head1 SEE ALSO
128            
129             Cache::Cache
130            
131             =head1 AUTHOR
132            
133             Original author: DeWitt Clinton <dewitt@unto.net>
134            
135             Last author: $Author: dclinton $
136            
137             Copyright (C) 2001-2003 DeWitt Clinton
138            
139             =cut
140