# Cache::BaseCache - perldoc - [phpMan]

## NAME
    [Cache::BaseCache](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3ABaseCache/markdown) -- abstract cache base class

## DESCRIPTION
    BaseCache provides functionality common to all instances of a cache. It differs from the
    CacheUtils package insofar as it is designed to be used as superclass for cache implementations.

## SYNOPSIS
    [Cache::BaseCache](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3ABaseCache/markdown) is to be used as a superclass for cache implementations. The most effective way
    to use BaseCache is to use the protected _set_backend method, which will be used to retrieve the
    persistence mechanism. The subclass can then inherit the BaseCache's implementation of get, set,
    etc. However, due to the difficulty inheriting static methods in Perl, the subclass will likely
    need to explicitly implement Clear, Purge, and Size. Also, a factory pattern should be used to
    invoke the _complete_initialization routine after the object is constructed.

      package [Cache::MyCache](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3AMyCache/markdown);

      use vars qw( @ISA );
      use [Cache::BaseCache](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3ABaseCache/markdown);
      use [Cache::MyBackend](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3AMyBackend/markdown);

      @ISA = qw( [Cache::BaseCache](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3ABaseCache/markdown) );

      sub new
      {
        my ( $self ) = _new( @_ );

        $self->_complete_initialization( );

        return $self;
      }

      sub _new
      {
        my ( $proto, $p_options_hash_ref ) = @_;
        my $class = ref( $proto ) || $proto;
        my $self = $class->[SUPER::_new](https://www.chedong.com/phpMan.php/perldoc/SUPER%3A%3Anew/markdown)( $p_options_hash_ref );
        $self->_set_backend( new [Cache::MyBackend](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3AMyBackend/markdown)( ) );
        return $self;
      }


      sub Clear
      {
        foreach my $namespace ( _Namespaces( ) )
        {
          _Get_Backend( )->delete_namespace( $namespace );
        }
      }


      sub Purge
      {
        foreach my $namespace ( _Namespaces( ) )
        {
          _Get_Cache( $namespace )->purge( );
        }
      }


      sub Size
      {
        my $size = 0;

        foreach my $namespace ( _Namespaces( ) )
        {
          $size += _Get_Cache( $namespace )->size( );
        }

        return $size;
      }

## SEE ALSO
    [Cache::Cache](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3ACache/markdown), [Cache::FileCache](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3AFileCache/markdown), [Cache::MemoryCache](https://www.chedong.com/phpMan.php/perldoc/Cache%3A%3AMemoryCache/markdown)

## AUTHOR
    Original author: DeWitt Clinton <<dewitt@unto.net>>

    Last author: $Author: dclinton $

    Copyright (C) 2001-2003 DeWitt Clinton

