info > CACHE::CACHE

๐Ÿ“› NAME

Cache::Cache -- the Cache interface.

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿ“ฆ Instantiate Cacheuse Cache::FileCache; my $cache = new Cache::FileCache( );Create a new file-based cache object
๐Ÿ’พ Set Data$cache->set( $key, $data, $expires_in );Store data with optional expiration time
๐Ÿ” Get Data$cache->get( $key );Retrieve data from cache
โŒ Remove Data$cache->remove( $key );Delete specific data from cache
๐Ÿงน Clear All$cache->clear( );Remove all data from the namespace
๐Ÿงผ Purge Expired$cache->purge( );Remove all expired objects from the namespace
๐Ÿ“ Get Size$cache->size( );Get total size of all cached objects
๐Ÿš€ SuccessorCHIActively developed successor to Cache::Cache

๐Ÿ“ DESCRIPTION

The Cache modules are designed to assist a developer in persisting data for a specified period of time. Often these modules are used in web applications to store data locally to save repeated and redundant expensive calls to remote machines or databases. People have also been known to use Cache::Cache for its straightforward interface in sharing data between runs of an application or invocations of a CGI-style script or simply as an easy to use abstraction of the filesystem or shared memory.

The Cache::Cache interface is implemented by classes that support the get, set, remove, size, purge, and clear instance methods and their corresponding static methods for persisting data across method calls.

โš–๏ธ CACHE::CACHE VERSUS CHI

Cache::Cache is in wide use and very stable, but has not changed in years and is no longer actively developed.

CHI is the successor to Cache::Cache. It adheres to the basic Cache::Cache API but adds new features and drivers (e.g. FastMmap and Memcached), improves performance, and addresses limitations in the Cache::Cache implementation. The authors recommend the use of CHI going forward.

Questions about Cache::Cache and CHI may be directed to the perl-cache mailing list at http://groups.google.com/group/perl-cache-discuss.

๐Ÿ’ก USAGE

First, choose the best type of cache implementation for your needs. The simplest cache is the MemoryCache, which is suitable for applications that are serving multiple sequential requests, and wish to avoid making redundant expensive queries, such as an Apache/mod_perl application talking to a database. If you wish to share that data between processes, then perhaps the SharedMemoryCache is appropriate, although its behavior is tightly bound to the underlying IPC mechanism, which varies from system to system, and is unsuitable for large objects or large numbers of objects. When the SharedMemoryCache is not acceptable, then FileCache offers all of the same functionality with similar performance metrics, and it is not limited in terms of the number of objects or their size. If you wish to maintain a strict limit on the size of a file system based cache, then the SizeAwareFileCache is the way to go. Similarly, the SizeAwareMemoryCache and the SizeAwareSharedMemoryCache add size management functionality to the MemoryCache and SharedMemoryCache classes respectively.

Using a cache is simple. Here is some sample code for instantiating and using a file system based cache.

  use Cache::FileCache;

  my $cache = new Cache::FileCache( );

  my $customer = $cache->get( $name );

  if ( not defined $customer )
  {
    $customer = get_customer_from_db( $name );
    $cache->set( $name, $customer, "10 minutes" );
  }

  return $customer;

๐Ÿ”ข CONSTANTS

โš™๏ธ METHODS

๐Ÿ”ง OPTIONS

The options are set by passing in a reference to a hash containing any of the following keys:

๐Ÿท๏ธ PROPERTIES

๐Ÿ“š SEE ALSO

CHI - the successor to Cache::Cache

Cache::Object, Cache::MemoryCache, Cache::FileCache, Cache::SharedMemoryCache, and Cache::SizeAwareFileCache

๐Ÿ‘ค AUTHOR

Original author: DeWitt Clinton <dewitt AT unto.net>

Last author: $Author: dclinton $

Copyright (C) 2001-2003 DeWitt Clinton

CACHE::CACHE
๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ“ DESCRIPTION โš–๏ธ CACHE::CACHE VERSUS CHI ๐Ÿ’ก USAGE ๐Ÿ”ข CONSTANTS โš™๏ธ METHODS ๐Ÿ”ง OPTIONS ๐Ÿท๏ธ PROPERTIES ๐Ÿ“š SEE ALSO ๐Ÿ‘ค AUTHOR

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-16 09:35 @2600:1f28:365:80b0:7cb9:fb:26c1:e368
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!