| 1 | package OpenInteract2::Cache::File; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # $Id: File.pm,v 1.12 2005/03/18 04:09:49 lachoy Exp $ | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use base qw( OpenInteract2::Cache ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Cache::FileCache; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Log::Log4perl qw( get_logger ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use OpenInteract2::Constants qw( :log ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use OpenInteract2::Context qw( CTX ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | $OpenInteract2::Cache::File::VERSION = sprintf("%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | my ( $log ); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | my $DEFAULT_SIZE = 2000000; # 10 MB -- max size of cache | |||||||||||||||||||
| 17 | 1 | my $DEFAULT_EXPIRE = 86400; # 1 day | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | ▶ | sub initialize { | ||||||||||||||||||
|
Subroutine
initialize: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 20 | 0 | my ( $self, $cache_conf ) = @_; | |||||||||||||||||||
| 21 | 0 | ▶ | $log ||= get_logger( LOG_CACHE ); | ||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.CACHE")
MC/DC0%0/2
$log ||= get_logger("OI2.CACHE")
$log
get_logger("OI2.CACHE")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.CACHE")
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # Allow values that are passed in to override anything | ||||||||||||||||||||
| 24 | # set in the config object | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | $cache_conf->{directory} ||= ''; | ||||||||||||||||||
|
Condition0%0/2
$cache_conf->{"directory"} ||= ""
MC/DC0%0/1
$cache_conf->{"directory"} ||= ""
$cache_conf->{"directory"}
Truth table0%0/2
A
A= $cache_conf->{"directory"}
| |||||||||||||||||||||
| 27 | 0 | ▶ | unless ( -d $cache_conf->{directory} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 0 | $log->error( "Cannot create a filesystem cache without a valid ", | |||||||||||||||||||
| 29 | "directory. (Given: $cache_conf->{directory})" ); | ||||||||||||||||||||
| 30 | 0 | return undef; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | my $cache_dir = $cache_conf->{directory}; | |||||||||||||||||||
| 34 | 0 | my $max_size = $cache_conf->{max_size}; | |||||||||||||||||||
| 35 | 0 | my $default_expire = $cache_conf->{default_expire}; | |||||||||||||||||||
| 36 | 0 | my $cache_depth = $cache_conf->{directory_depth}; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | # If a value isn't set, use the default from the class | ||||||||||||||||||||
| 39 | # configuration above. | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | $max_size ||= $DEFAULT_SIZE; | ||||||||||||||||||
|
Condition0%0/3
$max_size ||= $DEFAULT_SIZE
MC/DC0%0/2
$max_size ||= $DEFAULT_SIZE
$max_size
$DEFAULT_SIZE
Truth table0%0/3
A ||= B
A= $max_sizeB= $DEFAULT_SIZE
| |||||||||||||||||||||
| 42 | 0 | ▶ | $default_expire ||= $DEFAULT_EXPIRE; | ||||||||||||||||||
|
Condition0%0/3
$default_expire ||= $DEFAULT_EXPIRE
MC/DC0%0/2
$default_expire ||= $DEFAULT_EXPIRE
$default_expire
$DEFAULT_EXPIRE
Truth table0%0/3
A ||= B
A= $default_expireB= $DEFAULT_EXPIRE
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | $log->is_info && | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | $log->info( "Using the following cache settings ", | ||||||||||||||||||||
| 46 | "[Dir $cache_dir] [Size $max_size] ", | ||||||||||||||||||||
| 47 | "[Expire $default_expire] [Depth $cache_depth]" ); | ||||||||||||||||||||
| 48 | 0 | return Cache::FileCache->new({ | |||||||||||||||||||
| 49 | default_expires_in => $default_expire, | ||||||||||||||||||||
| 50 | max_size => $max_size, | ||||||||||||||||||||
| 51 | cache_root => $cache_dir, | ||||||||||||||||||||
| 52 | cache_depth => $cache_depth, | ||||||||||||||||||||
| 53 | }); | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | ▶ | sub purge_all { | ||||||||||||||||||
|
Subroutine
purge_all: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 57 | # no-op for now... | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | sub get_data { | ||||||||||||||||||
|
Subroutine
get_data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 61 | 0 | my ( $self, $cache, $key ) = @_; | |||||||||||||||||||
| 62 | 0 | ▶ | $log->is_debug && $log->debug( "Retrieving from '$key'" ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | return $cache->get( $key ); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | ▶ | sub set_data { | ||||||||||||||||||
|
Subroutine
set_data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 68 | 0 | my ( $self, $cache, $key, $data, $expires ) = @_; | |||||||||||||||||||
| 69 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | $log->debug( "Assigning to '$key' to expire in '$expires'" ); | ||||||||||||||||||||
| 71 | 0 | $cache->set( $key, $data, $expires ); | |||||||||||||||||||
| 72 | 0 | return 1; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | ▶ | sub clear_data { | ||||||||||||||||||
|
Subroutine
clear_data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 77 | 0 | my ( $self, $cache, $key ) = @_; | |||||||||||||||||||
| 78 | 0 | ▶ | $log->is_debug && $log->debug( "Removing cache item '$key'" ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 0 | $cache->remove( $key ); | |||||||||||||||||||
| 80 | 0 | return 1; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 1 | 1; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||