IPC::SharedCache 1.3 review

Download
by rbytes.net on

IPC::SharedCache is a Perl module to manage a cache in SysV IPC shared memory. SYNOPSIS use IPC::SharedCache; # the cach

License: Perl Artistic License
File size: 19K
Developer: Sam Tregar
0 stars award from rbytes.net

IPC::SharedCache is a Perl module to manage a cache in SysV IPC shared memory.

SYNOPSIS

use IPC::SharedCache;

# the cache is accessed using a tied hash.
tie %cache, 'IPC::SharedCache', ipc_key => 'AKEY',
load_callback => &load,
validate_callback => &validate;

# get an item from the cache
$config_file = $cache{'/some/path/to/some.config'};

This module provides a shared memory cache accessed as a tied hash.
Shared memory is an area of memory that is available to all processes. It is accessed by choosing a key, the ipc_key arguement to tie. Every process that accesses shared memory with the same key gets access to the same region of memory. In some ways it resembles a file system, but it is not hierarchical and it is resident in memory. This makes it harder to use than a filesystem but much faster. The data in shared memory persists until the machine is rebooted or it is explicitely deleted.

This module attempts to make shared memory easy to use for one specific application - a shared memory cache. For other uses of shared memory see the documentation to the excelent module I use, IPC::ShareLite (IPC::ShareLite).
A cache is a place where processes can store the results of their computations for use at a later time, possibly by other instances of the application. A good example of the use of a cache is a web server.

When a web server receieves a request for an html page it goes to the file system to read it. This is pretty slow, so the web server will probably save the file in memory and use the in memory copy the next time a request for that file comes in, as long as the file hasn't changed on disk.

This certainly speeds things up but web servers have to serve multiple clients at once, and that means multiple copies of the in-memory data. If the web server uses a shared memory cache, like the one this module provides, then all the servers can use the same cache and much less memory is consumed.

This module handles all shared memory interaction using the IPC::ShareLite module (version 0.06 and higher) and all data serialization using Storable. See IPC::ShareLite and Storable for details.

IPC::SharedCache 1.3 search tags