line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Role::Storage; |
2
|
6
|
|
|
6
|
|
3245
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
232
|
|
3
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
170
|
|
4
|
6
|
|
|
6
|
|
25
|
use Moo::Role; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Articulate::Role::Storage - caching functions |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This role provides retrieval methods which look for cached versions of |
13
|
|
|
|
|
|
|
the content desired before falling back to the canonical retrieval. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHODS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head3 get_content_cached |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->get_content_cached( $location ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get_content_cached { |
28
|
2
|
|
|
2
|
1
|
95
|
my $self = shift; |
29
|
2
|
|
|
|
|
22
|
my $location = shift->location; |
30
|
2
|
|
|
|
|
15
|
my $caching = $self->caching; |
31
|
2
|
50
|
|
|
|
241
|
if ( $caching->is_cached( content => $location ) ) { |
32
|
0
|
|
|
|
|
0
|
return $caching->get_cached( content => $location ); |
33
|
|
|
|
|
|
|
} |
34
|
2
|
|
|
|
|
12
|
my $content = $self->get_content($location); |
35
|
1
|
|
|
|
|
7
|
$caching->set_cache( content => $location, $content ); |
36
|
1
|
|
|
|
|
13
|
return $content; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head3 get_meta_cached |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->get_meta_cached( $location ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub get_meta_cached { |
46
|
2
|
|
|
2
|
1
|
67
|
my $self = shift; |
47
|
2
|
|
|
|
|
23
|
my $location = shift->location; |
48
|
2
|
|
|
|
|
17
|
my $caching = $self->caching; |
49
|
2
|
50
|
|
|
|
103
|
if ( $caching->is_cached( meta => $location ) ) { |
50
|
0
|
|
|
|
|
0
|
return $caching->get_cached( meta => $location ); |
51
|
|
|
|
|
|
|
} |
52
|
2
|
|
|
|
|
22
|
my $meta = $self->get_meta($location); |
53
|
1
|
|
|
|
|
3143
|
$caching->set_cache( meta => $location, $meta ); |
54
|
1
|
|
|
|
|
9
|
return $meta; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
around set_content => sub { |
58
|
|
|
|
|
|
|
my ( $orig, $self ) = ( shift, shift ); |
59
|
|
|
|
|
|
|
my $return = $self->$orig(@_); |
60
|
|
|
|
|
|
|
$self->caching->set_cache( content => $_[0], $return ); |
61
|
|
|
|
|
|
|
return $return; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
around set_meta => sub { |
65
|
|
|
|
|
|
|
my ( $orig, $self ) = ( shift, shift ); |
66
|
|
|
|
|
|
|
my $return = $self->$orig(@_); |
67
|
|
|
|
|
|
|
$self->caching->set_cache( meta => $_[0], $return ); |
68
|
|
|
|
|
|
|
return $return; |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
around delete_item => sub { |
72
|
|
|
|
|
|
|
my ( $orig, $self ) = ( shift, shift ); |
73
|
|
|
|
|
|
|
my $return = $self->$orig(@_); |
74
|
|
|
|
|
|
|
$self->caching->clear_cache( meta => $_[0] ); |
75
|
|
|
|
|
|
|
$self->caching->clear_cache( content => $_[0] ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# what about children? |
78
|
|
|
|
|
|
|
# Three possible approaches: |
79
|
|
|
|
|
|
|
# 1. clear cache of anything that looks le it might be a child |
80
|
|
|
|
|
|
|
# 2. storage deletion should recursively delete for all children |
81
|
|
|
|
|
|
|
# 3. storage should return an arrayref of items it deleted |
82
|
|
|
|
|
|
|
return $return; |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
around empty_all_content => sub { |
86
|
|
|
|
|
|
|
my ( $orig, $self ) = ( shift, shift ); |
87
|
|
|
|
|
|
|
my $return = $self->$orig(@_); |
88
|
|
|
|
|
|
|
$self->caching->empty_cache(); |
89
|
|
|
|
|
|
|
return $return; |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |