Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
awit-frameworks
awit-perl-toolkit
Commits
7e9eeee0
Commit
7e9eeee0
authored
Dec 22, 2010
by
Nigel Kukard
Browse files
* Allow overriding of cache file
* Allow changing owner & group of cache file
parent
bd228622
Changes
1
Show whitespace changes
Inline
Side-by-side
awitpt/cache.pm
View file @
7e9eeee0
...
...
@@ -89,14 +89,18 @@ sub Error
# Initialize cache
#
# @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
{
my
$server
=
shift
;
my
(
$server
,
$params
)
=
@_
;
my
$ch
;
#
Create Cache
$ch
=
Cache::
FastMmap
->
new
(
#
We going to pass these options to new()
my
%opt
=
(
'
page_size
'
=>
2048
,
'
num_pages
'
=>
1000
,
'
expire_time
'
=>
300
,
...
...
@@ -104,6 +108,40 @@ sub Init
'
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
$ch
->
set
('
Cache/Stats/Hit
',
0
);
$ch
->
set
('
Cache/Stats/Miss
',
0
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment