Subject: | Cache::SharedMemoryCache fails when more than one instance runs on the same server |
"[Thu Apr 15 17:35:06 2004] [error] Can't call method "fetch" on an undefined value at .../cpan/5.8.0-2003.05/lib/Cache/SharedMemoryBackend.pm line 98."
Hi
If you start seeing this type of error and your application was running fine until this point, it could mean that another process chain is also using the Cache::SharedMemoryCache module on the same machine.
I'm unsure as what is causing this error but I bet it has something to do with the Locking of IPC::ShareLite.
Note: using a separate namespace does not help getting through the problem. Switching to FileCache will help as a work around.
The test program given below will traps errors to avoid getting the generic 'Internal Server' message. The result should be that the
system time is cache upon the first http request (Apache Pid).
All other http requests (Apache Pids) should also see this
number. After 5 minutes has past the cache will clear itself
and a new time will be cached for all pids until the next rotation.
Load the sample once to see how it works normally. Load a
second apache instance with the same code and see the error
messages. Use netscape browser with <shift> <click 'reload'>.
# Apache 1.3.27 conf (requires mod-perl)
# include lib path in your @INC
PerlModule testShareMemCache
<Location /test>
SetHandler perl-script
PerlHandler testShareMemCache
</Location>
# file testShareMemCache.pm
package testShareMemCache;
use lib qw(../cpan/5.8.0-2003.05/lib);
use Cache::SharedMemoryCache;
my $cache = new Cache::SharedMemoryCache;
Apache->server->register_cleanup(sub {$cache->clear;});
my $pid = $$;
sub handler
{
my $r = shift;
my $time = eval{$cache->get('TiMeStAmP')};
if (!$time) {
$time = time;
eval{$cache->set('TiMeStAmP',$time,'5 min')};
}
print '<html><head>
<title>Testing Cache::SharedMemoryCache</title>
</head><body>',
"Parent pid: $pid
<h3>System Clock: $time Apache Pid: $$</h3>
$@</body></html>";
return OK;
}
1;
I was running on Perl 5.8.0 mod-perl 1.27 for apache 1.3.27 on Solaris 5.8
IPC::ShareLite v0.09
Cache::Cache v1.40
Cache::SharedMemoryCache v1.23
Cache::SharedMemoryBackend v1.7
If I could make a suggestion:
The problem may turn out to be a module dependency (IPC). It would better help the developer if the external error was trapped, like using an eval block or testing $p_ipc_identifier for a null value.
From error block SharedMemoryBackend:
sub _Restore_Shared_Hash_Ref
{
my ( $p_ipc_identifier ) = Static_Params( @_ );
Assert_Defined( $p_ipc_identifier );
my $frozen_hash_ref = _Instantiate_Share( $p_ipc_identifier )->fetch( ) or
return { };
return Thaw_Data( $frozen_hash_ref );
}
If this turns out to be some platform limitation, please make a note of this in the perldocs.
Regards
Tom Acunzo Ubs Investment Bank (IMS Perot Systems)