info > Cache::Cache

Cache::Cache(3pm) โ€” User Contributed Perl Documentation

๐Ÿ“› NAME

Cache::Cache โ€” the Cache interface.

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿ”ง Create a new cachemy $cache = new Cache::FileCache( \%options )Construct a new cache instance with optional configuration hash
๐Ÿ“– Retrieve cached data$cache->get( $key )Return data associated with the given key
๐Ÿ’พ Store data with expiration$cache->set( $key, $data, $expires_in )Associate data with key; expiration in seconds or string like "10 minutes"
๐Ÿ—‘๏ธ Remove a cached item$cache->remove( $key )Delete the data associated with the key from the cache
๐Ÿงน Purge expired items$cache->purge()Remove all objects that have expired from the namespace
๐Ÿงผ Clear all items$cache->clear()Remove all objects from the namespace associated with this instance
๐Ÿ“ Get cache size$cache->size()Return total size of all objects in the namespace
๐Ÿ” Get underlying object$cache->get_object( $key )Return the Cache::Object; does not trigger removal even if expired

๐Ÿ“– 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

๐Ÿ“ฆ Static Methods

๐Ÿ†• Constructor

๐Ÿ”ง Instance Methods

โš™๏ธ OPTIONS

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

๐Ÿท๏ธ PROPERTIES

๐Ÿ“š SEE ALSO

โœ๏ธ AUTHOR

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

Last author: $Author: dclinton $

Copyright (C) 2001-2003 DeWitt Clinton


perl v5.20.2 โ€” 2015-01-22 โ€” Cache::Cache(3pm)

Cache::Cache
Cache::Cache(3pm) โ€” User Contributed Perl Documentation ๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ“– DESCRIPTION
๐Ÿ”„ CACHE::CACHE VERSUS CHI
๐Ÿ”ง USAGE ๐Ÿ“Œ CONSTANTS โš™๏ธ METHODS
๐Ÿ“ฆ Static Methods ๐Ÿ†• Constructor ๐Ÿ”ง Instance Methods
โš™๏ธ OPTIONS ๐Ÿท๏ธ PROPERTIES ๐Ÿ“š SEE ALSO โœ๏ธ AUTHOR

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-14 21:52 @2600:1f28:365:80b0:4d23:66fa:c2bb:7bae
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!