Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
IPC::SharedCache - a Perl module to manage a cache in SysV IPC shared


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 (L<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 L<IPC::ShareLite> and L<Storable>
for details.


This module began its life as an internal piece of HTML::Template (see
L<HTML::Template>).  HTML::Template has the ability to maintain a
cache of parsed template structures when running in a persistent
environment like Apache/mod_perl.  Since parsing a template from disk
takes a fair ammount of time this can provide a big performance gain.
Unfortunately it can also consume large ammounts of memory since each
web server maintains its own cache in its own memory space.

By using IPC::ShareLite and Storable (L<IPC::ShareLite> and
L<Storable>), HTML::Template was able to maintain a single shared
cache of templates.  The downside was that HTML::Template's cache
routines became complicated by a lot of IPC code.  My solution is to
break out the IPC cache mechanisms into their own module,
IPC::SharedCache.  Hopefully over time it can become general enough to
be usable by more than just HTML::Template.


In case this is your first module, the usual methods are:

        perl Makefile.PL
        make test
        make install

You will need to have IPC::ShareLite (at least version 0.06) and
Storable installed to use this module.  If you want to use the 'walk'
function, you'll need Data::Dumper.  All these are available on CPAN


The documentation is in in the form of POD format
perldocs.  Even the above text might be out of date, so be sure to
check the perldocs for the straight truth!


This module was written by Sam Tregar (  


IPC::SharedCache - a Perl module to manage a SysV IPC shared cache.
Copyright (C) 2000 Sam Tregar (

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307