| 1 |
IPC::SharedCache - a Perl module to manage a cache in SysV IPC shared |
| 2 |
memory. |
| 3 |
|
| 4 |
DESCRIPTION |
| 5 |
|
| 6 |
This module provides a shared memory cache accessed as a tied hash. |
| 7 |
|
| 8 |
Shared memory is an area of memory that is available to all processes. |
| 9 |
It is accessed by choosing a key, the ipc_key arguement to tie. Every |
| 10 |
process that accesses shared memory with the same key gets access to |
| 11 |
the same region of memory. In some ways it resembles a file system, |
| 12 |
but it is not hierarchical and it is resident in memory. This makes |
| 13 |
it harder to use than a filesystem but much faster. The data in |
| 14 |
shared memory persists until the machine is rebooted or it is |
| 15 |
explicitely deleted. |
| 16 |
|
| 17 |
This module attempts to make shared memory easy to use for one |
| 18 |
specific application - a shared memory cache. For other uses of |
| 19 |
shared memory see the documentation to the excelent module I use, |
| 20 |
IPC::ShareLite (L<IPC::ShareLite>). |
| 21 |
|
| 22 |
A cache is a place where processes can store the results of their |
| 23 |
computations for use at a later time, possibly by other instances of |
| 24 |
the application. A good example of the use of a cache is a web |
| 25 |
server. When a web server receieves a request for an html page it |
| 26 |
goes to the file system to read it. This is pretty slow, so the web |
| 27 |
server will probably save the file in memory and use the in memory |
| 28 |
copy the next time a request for that file comes in, as long as the |
| 29 |
file hasn't changed on disk. This certainly speeds things up but web |
| 30 |
servers have to serve multiple clients at once, and that means |
| 31 |
multiple copies of the in-memory data. If the web server uses a |
| 32 |
shared memory cache, like the one this module provides, then all the |
| 33 |
servers can use the same cache and much less memory is consumed. |
| 34 |
|
| 35 |
This module handles all shared memory interaction using the |
| 36 |
IPC::ShareLite module (version 0.06 and higher) and all data |
| 37 |
serialization using Storable. See L<IPC::ShareLite> and L<Storable> |
| 38 |
for details. |
| 39 |
|
| 40 |
MOTIVATION |
| 41 |
|
| 42 |
This module began its life as an internal piece of HTML::Template (see |
| 43 |
L<HTML::Template>). HTML::Template has the ability to maintain a |
| 44 |
cache of parsed template structures when running in a persistent |
| 45 |
environment like Apache/mod_perl. Since parsing a template from disk |
| 46 |
takes a fair ammount of time this can provide a big performance gain. |
| 47 |
Unfortunately it can also consume large ammounts of memory since each |
| 48 |
web server maintains its own cache in its own memory space. |
| 49 |
|
| 50 |
By using IPC::ShareLite and Storable (L<IPC::ShareLite> and |
| 51 |
L<Storable>), HTML::Template was able to maintain a single shared |
| 52 |
cache of templates. The downside was that HTML::Template's cache |
| 53 |
routines became complicated by a lot of IPC code. My solution is to |
| 54 |
break out the IPC cache mechanisms into their own module, |
| 55 |
IPC::SharedCache. Hopefully over time it can become general enough to |
| 56 |
be usable by more than just HTML::Template. |
| 57 |
|
| 58 |
INSTALLATION |
| 59 |
|
| 60 |
In case this is your first module, the usual methods are: |
| 61 |
|
| 62 |
perl Makefile.PL |
| 63 |
make |
| 64 |
make test |
| 65 |
make install |
| 66 |
|
| 67 |
You will need to have IPC::ShareLite (at least version 0.06) and |
| 68 |
Storable installed to use this module. If you want to use the 'walk' |
| 69 |
function, you'll need Data::Dumper. All these are available on CPAN |
| 70 |
(www.cpan.org). |
| 71 |
|
| 72 |
DOCUMENTATION |
| 73 |
|
| 74 |
The documentation is in SharedCache.pm in the form of POD format |
| 75 |
perldocs. Even the above text might be out of date, so be sure to |
| 76 |
check the perldocs for the straight truth! |
| 77 |
|
| 78 |
CONTACT INFO |
| 79 |
|
| 80 |
This module was written by Sam Tregar ([email protected]). |
| 81 |
|
| 82 |
LICENSE |
| 83 |
|
| 84 |
IPC::SharedCache - a Perl module to manage a SysV IPC shared cache. |
| 85 |
Copyright (C) 2000 Sam Tregar ([email protected]) |
| 86 |
|
| 87 |
This program is free software; you can redistribute it and/or modify |
| 88 |
it under the terms of the GNU General Public License as published by |
| 89 |
the Free Software Foundation; either version 2 of the License, or (at |
| 90 |
your option) any later version. |
| 91 |
|
| 92 |
This program is distributed in the hope that it will be useful, but |
| 93 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 94 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 95 |
General Public License for more details. |
| 96 |
|
| 97 |
You should have received a copy of the GNU General Public License |
| 98 |
along with this program; if not, write to the Free Software |
| 99 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 100 |
USA |