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 / SharedMemoryCache.pm < prev    next >
Encoding:
Perl POD Document  |  2003-04-15  |  2.6 KB  |  153 lines

  1. ######################################################################
  2. # $Id: SharedMemoryCache.pm,v 1.23 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::SharedMemoryCache;
  13.  
  14.  
  15. use strict;
  16. use vars qw( @ISA );
  17. use Cache::Cache;
  18. use Cache::MemoryCache;
  19. use Cache::CacheUtils qw( Assert_Defined Static_Params );
  20. use Cache::SharedMemoryBackend;
  21. use Error;
  22.  
  23.  
  24. @ISA = qw ( Cache::MemoryCache );
  25.  
  26.  
  27. sub Clear
  28. {
  29.   foreach my $namespace ( _Namespaces( ) )
  30.   {
  31.     _Get_Backend( )->delete_namespace( $namespace );
  32.   }
  33. }
  34.  
  35.  
  36. sub Purge
  37. {
  38.   foreach my $namespace ( _Namespaces( ) )
  39.   {
  40.     _Get_Cache( $namespace )->purge( );
  41.   }
  42. }
  43.  
  44.  
  45. sub Size
  46. {
  47.   my $size = 0;
  48.  
  49.   foreach my $namespace ( _Namespaces( ) )
  50.   {
  51.     $size += _Get_Cache( $namespace )->size( );
  52.   }
  53.  
  54.   return $size;
  55. }
  56.  
  57.  
  58. sub _Namespaces
  59. {
  60.   return _Get_Backend( )->get_namespaces( );
  61. }
  62.  
  63.  
  64.  
  65. sub _Get_Backend
  66. {
  67.   return new Cache::SharedMemoryBackend( );
  68. }
  69.  
  70.  
  71. sub _Get_Cache
  72. {
  73.   my ( $p_namespace ) = Static_Params( @_ );
  74.  
  75.   Assert_Defined( $p_namespace );
  76.  
  77.   return new Cache::SharedMemoryCache( { 'namespace' => $p_namespace } );
  78. }
  79.  
  80.  
  81. sub new
  82. {
  83.   my ( $self ) = _new( @_ );
  84.  
  85.   $self->_complete_initialization( );
  86.  
  87.   return $self;
  88. }
  89.  
  90.  
  91. sub _new
  92. {
  93.   my ( $proto, $p_options_hash_ref ) = @_;
  94.   my $class = ref( $proto ) || $proto;
  95.   my $self = $class->SUPER::_new( $p_options_hash_ref );
  96.   $self->_set_backend( new Cache::SharedMemoryBackend( ) );
  97.   return $self;
  98. }
  99.  
  100.  
  101. 1;
  102.  
  103.  
  104.  
  105. =pod
  106.  
  107. =head1 NAME
  108.  
  109. Cache::SharedMemoryCache -- extends the MemoryCache.
  110.  
  111. =head1 DESCRIPTION
  112.  
  113. The SharedMemoryCache extends the MemoryCache class and binds the data
  114. store to shared memory so that separate process can use the same
  115. cache.
  116.  
  117. =head1 SYNOPSIS
  118.  
  119.   use Cache::SharedMemoryCache;
  120.  
  121.   my %cache_options_= ( 'namespace' => 'MyNamespace',
  122.             'default_expires_in' => 600 );
  123.  
  124.   my $shared_memory_cache = 
  125.     new Cache::SharedMemoryCache( \%cache_options ) or
  126.       croak( "Couldn't instantiate SharedMemoryCache" );
  127.  
  128. =head1 METHODS
  129.  
  130. See Cache::Cache for the API documentation.
  131.  
  132. =head1 OPTIONS
  133.  
  134. See Cache::Cache for the standard options.
  135.  
  136. =head1 PROPERTIES
  137.  
  138. See Cache::Cache for the default properties.
  139.  
  140. =head1 SEE ALSO
  141.  
  142. Cache::Cache, Cache::MemoryCache
  143.  
  144. =head1 AUTHOR
  145.  
  146. Original author: DeWitt Clinton <dewitt@unto.net>
  147.  
  148. Last author:     $Author: dclinton $
  149.  
  150. Copyright (C) 2001-2003 DeWitt Clinton
  151.  
  152. =cut
  153.