GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  IPC::CACHE (3)

.ds Aq ’

NAME

IPC::Cache - a perl module that implements an object storage space where data is persisted across process boundaries

CONTENTS

SYNOPSIS

use IPC::Cache;

# create a cache in the specified namespace, where objects # will expire in one day

my $cache = new Cache( { namespace => ’MyCache’,
expires_in => 86400 } );

# store a value in the cache (will expire in one day)

$cache->set(key1, value1);

# retrieve a value from the cache

$cache->get(key1);

# store a value that expires in one hour

$cache->set(key2, value2, 3600);

# clear this cache’s contents

$cache->clear();

# delete all namespaces from shared memory

IPC::Cache::CLEAR();

DESCRIPTION

IPC::Cache is used to persist data across processes via shared memory.

    TYPICAL USAGE

A typical scenario for this would be a mod_perl or perl CGI application. In a multi-tier architecture, it is likely that a trip from the front-end to the database is the most expensive operation, and that data may not change frequently. Using this module will help keep that data on the front-end.

Consider the following usage in a mod_perl application, where a mod_perl application serves out images that are retrieved from a database. Those images change infrequently, but we want to check them once an hour, just in case.

my $cache = new Cache( { namespace => ’Images’,
expires_in => 3600 } );

my $image = $imageCache->get(the_requested_image);

if (!$image) {



    # $image = [expensive database call to get the image]

    $cache->set("the_requested_image", $image);



}

That bit of code, executed in any instance of the mod_perl/httpd process will first try the shared memory cache, and only perform the expensive database call if the image has not been fetched before, has timed out, or the cache has been cleared.

    METHODS

<B>new(\%options)B> Creates a new instance of the cache object. The constructor takes a reference to an options hash which can contain any or all of the following:
$options{namespace} Namespaces provide isolation between objects. Each cache refers to one and only one namespace. Multiple caches can refer to the same namespace, however. While specifying a namespace is not required, it is recommended so as not to have data collide.
$options{expires_in} If the expires_in option is set, all objects in this cache will be cleared in that number of seconds. It can be overridden on a per-object basis. If expires_in is not set, the objects will never expire unless explicitly set.
$options{cache_key} The cache_key is used to determine the underlying shared memory segment to use. In typical usage, leaving this unset and relying on namespaces alone will be more than adequate.
<B>set($identifier, B>$object<B>, B>$expires_in<B>)B> Adds an object to the cache. set takes the following parameters:
$identifier The key the refers to this object.
$object The object to be stored.
$expires_in (optional) The object will be cleared from the cache in this number of seconds. Overrides the default expire_in for the cache.
<B>get($identifier)B> Retrieves an object from the cache. get takes the following parameter:
$identifier The key referring to the object to be retrieved.
<B>B>clear()<B>B> Removes all objects from this cache.
<B>B>purge()<B>B> Removes all objects that have expired
<B>IPC::Cache::CLEAR($cache_key)B> Removes this cache and all the associated namespaces from shared memory. CLEAR takes the following parameter:
$cache_key (optional) Specifies the shared memory segment to be cleared. Needed only if a cache was created in a non-standard shared memory segment.
<B>IPC::Cache::PURGE($cache_key)B> Removes all objects in all namespaces that have expired. PURGE takes the following parameter:
$cache_key (optional) Specifies the shared memory segment to be purged. Needed only if a cache was created in a non-standard shared memory segment.
<B>IPC::Cache::SIZE($cache_key)B> Roughly estimates the amount of memory in use. SIZE takes the following parameter:
$cache_key (optional) Specifies the shared memory segment to be examined. Needed only if a cache was created in a non-standard shared memory segment.

BUGS

o The SIZE method estimates only the size of the frozen data, not the actual shared memory usage
o There is no mechanism for limiting the amount of memory in use

AUTHOR

DeWitt Clinton <dclinton@eziba.com>
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 CACHE (3) 2000-02-01

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.