Commit 76decc12 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Allow caching of complex data objects

parent 919df77f
......@@ -29,10 +29,13 @@ our (@ISA,@EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
cacheStoreKeyPair
cacheStoreComplexKeyPair
cacheGetKeyPair
cacheGetComplexKeyPair
);
use Cache::FastMmap;
use Storable;
# Cache stuff
my $cache_type = "FastMmap";
......@@ -190,6 +193,47 @@ sub cacheGetKeyPair
}
# Store a complex item
# Parameters:
# CacheName - Name of cache we storing things in
# Key - Item key
# Value - Item value
sub cacheStoreComplexKeyPair
{
my ($cacheName,$key,$value) = @_;
my $rawValue = Storable::freeze($value);
if (!defined($rawValue)) {
setError("Unable to freeze cache value in '$cacheName'");
return -1;
}
return cacheStoreKeyPair($cacheName,$key,$rawValue);
}
# Get a complex item
# Parameters:
# CacheName - Name of cache we storing things in
# Key - Item key
sub cacheGetComplexKeyPair
{
my ($cacheName,$key) = @_;
my ($res,$rawValue) = cacheGetKeyPair($cacheName,$key);
# Thaw out item, if there is no error and we are defined
if (!$res && defined($rawValue)) {
$rawValue = Storable::thaw($rawValue);
}
return ($res,$rawValue);
}
# Return cache hit ratio
sub getHitRatio
{
......
Supports Markdown
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