Commit 992d9495 authored by Vincent Danjean's avatar Vincent Danjean

[svn-inject] Installing original source of libipc-sharedcache-perl

parents
ANNOUNCEMENT: NEW MODULE: IPC::SharedCache 1.3
IPC::SharedCache - a Perl module to manage a cache in SysV IPC shared
memory.
CHANGES
1.3
- Bug Fix: missing _unlock() in DELETE rectified. (Ed Loehr)
- Bug Fix: callback array refs were being eaten on cache access.
(Maverick)
SHORT DESCRIPTION
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.
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.
This module is licenced under the GPL. See the LICENCE section of the
README.
AVAILABILITY
This module is available on SourceForge. Download it at:
http://download.sourceforge.net/HTML-Template/IPC-SharedCache-1.3.tar.gz
The module is also available on CPAN. You can get it using CPAN.pm or
go to:
http://www.cpan.org/authors/id/S/SA/SAMTREGAR/
MOTIVATION
This module began its life as an internal piece of 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, 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.
DOCUMENTATION
The documentation is in SharedCache.pm 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.
CONTACT INFO
This module was written by Sam Tregar (sam@tregar.com).
Revision history for Perl extension IPC::SharedCache.
1.0 Fri February 17, 2000 12:00:00
- original version, broken off from HTML::Template and rewritten
from scratch.
1.1 Wed February 23, 2000 12:00:00
- Bug Fix, load_callback was being called incorrectly the first
time - thanks to Roland Mas for the spot!
- Bug Fix, added workaround for "panic: POPSTACK", thanks to
Drew Taylor.
1.2 Sun March 05, 2000 12:00:00
- Bug Fix: validate_callback was effectively ignored!
1.3 Fri March 24, 2000 12:00:00
- Bug Fix: missing _unlock() in DELETE rectified. (Ed Loehr)
- Bug Fix: callback array refs were being eaten on cache access.
(Maverick)
This diff is collapsed.
Changes
MANIFEST
Makefile.PL
SharedCache.pm
test.pl
LICENSE
README
ANNOUNCE
use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => 'IPC::SharedCache',
'VERSION_FROM' => 'SharedCache.pm', # finds $VERSION
'PREREQ_PM' => {
'IPC::ShareLite' => '0.06',
'Storable' => '0',
'Carp' => '0',
'IPC::SysV' => '0'
},
);
IPC::SharedCache - a Perl module to manage a cache in SysV IPC shared
memory.
DESCRIPTION
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.
MOTIVATION
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.
INSTALLATION
In case this is your first module, the usual methods are:
perl Makefile.PL
make
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
(www.cpan.org).
DOCUMENTATION
The documentation is in SharedCache.pm 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!
CONTACT INFO
This module was written by Sam Tregar (sam@tregar.com).
LICENSE
IPC::SharedCache - a Perl module to manage a SysV IPC shared cache.
Copyright (C) 2000 Sam Tregar (sam@tregar.com)
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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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
USA
This diff is collapsed.
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..9\n"; }
END {print "not ok 1\n" unless $loaded;}
use IPC::SharedCache;
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
use IPC::SharedCache;
local($^W) = 1;
# test creation
my %cache;
tie %cache, 'IPC::SharedCache',
ipc_key => 'MYKI',
load_callback => sub { return [time(), time(), time()] },
validate_callback => sub { return 1; },
debug => 0;
print "ok 2\n";
# test load
my $time_array = $cache{'some_key'};
die "not ok 3\n" unless defined($time_array);
die "not ok 3\n" unless ref($time_array) eq 'ARRAY';
print "ok 3\n";
# test delete/exists
delete($cache{'some_key'});
die "not ok 4\n" if exists($cache{'some_key'});
print "ok 4\n";
# test delete/exists
$time_array = $cache{'some_other_key'};
die "not ok 5\n" unless exists($cache{'some_other_key'});
print "ok 5\n";
delete($cache{'some_other_key'});
# test keys/each
my $a = $cache{'a'};
my $b = $cache{'b'};
my $c = $cache{'c'};
die "not ok 6\n" unless keys(%cache) == 3;
die "not ok 6\n" unless (keys(%cache))[0] eq 'a';
die "not ok 6\n" unless (keys(%cache))[1] eq 'b';
die "not ok 6\n" unless (keys(%cache))[2] eq 'c';
my @keys = keys(%cache);
for (my $x = 0; $x < 3; $x++) {
die "not ok 6\n"
unless ($keys[$x] eq scalar(each(%cache)));
}
delete($cache{'a'});
die "not ok 6\n" unless keys(%cache) == 2;
die "not ok 6\n" unless (keys(%cache))[0] eq 'b';
die "not ok 6\n" unless (keys(%cache))[1] eq 'c';
delete($cache{'b'});
die "not ok 6\n" unless keys(%cache) == 1;
die "not ok 6\n" unless (keys(%cache))[0] eq 'c';
delete($cache{'c'});
die "not ok 6\n" unless keys(%cache) == 0;
print "ok 6\n";
# clean up with remove
untie %cache;
IPC::SharedCache::remove('MYKI');
# test max_size
my %mcache;
tie %mcache, 'IPC::SharedCache',
ipc_key => 'MYKI',
load_callback => sub { my $data = 'a' x 1024; return [ $data ]; },
validate_callback => sub { return 1; },
max_size => 4500,
debug => 0;
print "ok 7\n";
# fill the cache
my $f = $mcache{'f'};
my $g = $mcache{'g'};
my $h = $mcache{'h'};
my $i = $mcache{'i'};
die "not ok 8\n" unless scalar(keys(%mcache)) == 4;
print "ok 8\n";
# this should make the cache delete 'f' by crossing max_size:
my $j = $mcache{'j'};
die "not ok 9\n" unless keys(%mcache) == 4;
die "not ok 9\n" unless (keys(%mcache))[0] eq 'g';
die "not ok 9\n" unless (keys(%mcache))[1] eq 'h';
die "not ok 9\n" unless (keys(%mcache))[2] eq 'i';
die "not ok 9\n" unless (keys(%mcache))[3] eq 'j';
print "ok 9\n";
# clean up
untie %mcache;
IPC::SharedCache::remove('MYKI');
#my %cache;
#tie %cache, 'IPC::SharedCache',
# ipc_key => 'MYKI',
# load_callback => sub { die "blah" },
# validate_callback => sub { return 1; },
# max_size => 4500,
# debug => 0;
#print "ok 10\n";
#
#my $z = $cache{'z'};
#
#{
# print "ok 11\n";
#}
# IPC::SharedCache::remove('MYKI');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment