Skip to content
Snippets Groups Projects
Commit 7e9eeee0 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Allow overriding of cache file

* Allow changing owner & group of cache file
parent bd228622
No related branches found
No related tags found
No related merge requests found
...@@ -89,14 +89,18 @@ sub Error ...@@ -89,14 +89,18 @@ sub Error
# Initialize cache # Initialize cache
# #
# @param server Server object # @param server Server object
# @param params Parameters for the cache
# @li cache_file Filename of the cache file
# @li cache_file_user Owner of the cache file
# @li cache_file_group Group of the cache file
sub Init sub Init
{ {
my $server = shift; my ($server,$params) = @_;
my $ch; my $ch;
# Create Cache # We going to pass these options to new()
$ch = Cache::FastMmap->new( my %opt = (
'page_size' => 2048, 'page_size' => 2048,
'num_pages' => 1000, 'num_pages' => 1000,
'expire_time' => 300, 'expire_time' => 300,
...@@ -104,6 +108,40 @@ sub Init ...@@ -104,6 +108,40 @@ sub Init
'unlink_on_exit' => 1, 'unlink_on_exit' => 1,
); );
# Check if we have the optional $params
if (defined($params)) {
# If we have a special cache file, use it and init it too
if (defined($params->{'cache_file'})) {
$opt{'share_file'} = $params->{'cache_file'};
$opt{'init_file'} = 1;
}
}
# Create Cache
$ch = Cache::FastMmap->new(%opt);
# Check if we have the optional $params
if (defined($params)) {
# If we have an explicit owner set, use it
if (defined($params->{'cache_file_user'})) {
# Check all is ok...
my ($chown_user,$chown_group);
if (!($chown_user = getpwnam($params->{'cache_file_user'}))) {
setError("User '$chown_user' appears to be invalid: $?");
return(-1);
}
if (!($chown_group = getpwnam($params->{'cache_file_group'}))) {
setError("Group '$chown_group' appears to be invalid: $?");
return(-1);
}
# Go in and chown it
if (!chown($chown_user,$chown_group,$opt{'share_file'})) {
setError("Failed to chown cache file '".$opt{'share_file'}."': $!");
return(-1);
}
}
}
# Stats # Stats
$ch->set('Cache/Stats/Hit',0); $ch->set('Cache/Stats/Hit',0);
$ch->set('Cache/Stats/Miss',0); $ch->set('Cache/Stats/Miss',0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment