home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / MemoryCache.pm < prev    next >
Encoding:
Perl POD Document  |  2003-04-15  |  2.8 KB  |  152 lines

  1. ######################################################################
  2. # $Id: MemoryCache.pm,v 1.28 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::MemoryCache;
  13.  
  14.  
  15. use strict;
  16. use vars qw( @ISA );
  17. use Cache::BaseCache;
  18. use Cache::Cache qw( $EXPIRES_NEVER );
  19. use Cache::CacheUtils qw( Assert_Defined Static_Params );
  20. use Cache::MemoryBackend;
  21.  
  22. @ISA = qw ( Cache::BaseCache );
  23.  
  24.  
  25. sub Clear
  26. {
  27.   foreach my $namespace ( _Namespaces( ) )
  28.   {
  29.     _Get_Backend( )->delete_namespace( $namespace );
  30.   }
  31. }
  32.  
  33.  
  34. sub Purge
  35. {
  36.   foreach my $namespace ( _Namespaces( ) )
  37.   {
  38.     _Get_Cache( $namespace )->purge( );
  39.   }
  40. }
  41.  
  42.  
  43. sub Size
  44. {
  45.   my $size = 0;
  46.  
  47.   foreach my $namespace ( _Namespaces( ) )
  48.   {
  49.     $size += _Get_Cache( $namespace )->size( );
  50.   }
  51.  
  52.   return $size;
  53. }
  54.  
  55.  
  56. sub _Get_Backend
  57. {
  58.   return new Cache::MemoryBackend( );
  59. }
  60.  
  61.  
  62. sub _Namespaces
  63. {
  64.   return _Get_Backend( )->get_namespaces( );
  65. }
  66.  
  67.  
  68. sub _Get_Cache
  69. {
  70.   my ( $p_namespace ) = Static_Params( @_ );
  71.  
  72.   Assert_Defined( $p_namespace );
  73.  
  74.   return new Cache::MemoryCache( { 'namespace' => $p_namespace } );
  75. }
  76.  
  77.  
  78. sub new
  79. {
  80.   my ( $self ) = _new( @_ );
  81.  
  82.   $self->_complete_initialization( );
  83.  
  84.   return $self;
  85. }
  86.  
  87.  
  88. sub _new
  89. {
  90.   my ( $proto, $p_options_hash_ref ) = @_;
  91.   my $class = ref( $proto ) || $proto;
  92.   my $self = $class->SUPER::_new( $p_options_hash_ref );
  93.   $self->_set_backend( new Cache::MemoryBackend( ) );
  94.   return $self;
  95. }
  96.  
  97.  
  98. 1;
  99.  
  100.  
  101. __END__
  102.  
  103. =pod
  104.  
  105. =head1 NAME
  106.  
  107. Cache::MemoryCache -- implements the Cache interface.
  108.  
  109. =head1 DESCRIPTION
  110.  
  111. The MemoryCache class implements the Cache interface.  This cache
  112. stores data on a per-process basis.  This is the fastest of the cache
  113. implementations, but data can not be shared between processes with the
  114. MemoryCache.  However, the data will remain in the cache until
  115. cleared, it expires, or the process dies.  The cache object simply
  116. going out of scope will not destroy the data.
  117.  
  118. =head1 SYNOPSIS
  119.  
  120.   use Cache::MemoryCache;
  121.  
  122.   my $cache = new Cache::MemoryCache( { 'namespace' => 'MyNamespace',
  123.                                         'default_expires_in' => 600 } );
  124.  
  125.   See Cache::Cache for the usage synopsis.
  126.  
  127. =head1 METHODS
  128.  
  129. See Cache::Cache for the API documentation.
  130.  
  131. =head1 OPTIONS
  132.  
  133. See Cache::Cache for standard options.
  134.  
  135. =head1 PROPERTIES
  136.  
  137. See Cache::Cache for default properties.
  138.  
  139. =head1 SEE ALSO
  140.  
  141. Cache::Cache
  142.  
  143. =head1 AUTHOR
  144.  
  145. Original author: DeWitt Clinton <dewitt@unto.net>
  146.  
  147. Last author:     $Author: dclinton $
  148.  
  149. Copyright (C) 2001-2003 DeWitt Clinton
  150.  
  151. =cut
  152.