| 1 | package Articulate::Caching; | ||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 6 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 6 | ▶ | use Articulate::Syntax qw(instantiate_array); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 6 | ▶ | use Articulate::Item; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 6 | with 'Articulate::Role::Component'; | |||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | Articulate::Caching - store and retrieve content quickly | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | =head1 CONFIGURATION | ||||||||||
| 18 | |||||||||||
| 19 | components: | ||||||||||
| 20 | caching: | ||||||||||
| 21 | Articulate::Caching: | ||||||||||
| 22 | providers: | ||||||||||
| 23 | - Articulate::Caching::Native | ||||||||||
| 24 | |||||||||||
| 25 | =head1 ATTRIBUTE | ||||||||||
| 26 | |||||||||||
| 27 | =head3 providers | ||||||||||
| 28 | |||||||||||
| 29 | A list of classes which can be used to cache items. | ||||||||||
| 30 | |||||||||||
| 31 | =cut | ||||||||||
| 32 | |||||||||||
| 33 | has providers => ( | ||||||||||
| 34 | is => 'rw', | ||||||||||
| 35 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 5 | ▶ | coerce => sub { instantiate_array(@_) } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 6 | ); | |||||||||
| 38 | |||||||||||
| 39 | =head1 METHODS | ||||||||||
| 40 | |||||||||||
| 41 | =head3 is_cached | ||||||||||
| 42 | |||||||||||
| 43 | $caching->is_cached( $what, $location ) | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | 6 | ▶ | sub is_cached { | ||||||||
|
Subroutine
is_cached: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 48 | 6 | my $self = shift; | |||||||||
| 49 | 6 | my $what = shift; | |||||||||
| 50 | 6 | my $location = shift; | |||||||||
| 51 | 6 | foreach my $provider ( @{ $self->providers } ) { | |||||||||
| 52 | 6 | ▶ | return 1 if $provider->is_cached( $what, $location ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | } | ||||||||||
| 54 | 6 | return 0; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | =head3 get_cached | ||||||||||
| 58 | |||||||||||
| 59 | $caching->get_cached( $what, $location ) | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub get_cached { | ||||||||
|
Subroutine
get_cached: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 64 | 0 | my $self = shift; | |||||||||
| 65 | 0 | my $what = shift; | |||||||||
| 66 | 0 | my $location = shift; | |||||||||
| 67 | 0 | foreach my $provider ( @{ $self->providers } ) { | |||||||||
| 68 | 0 | ▶ | return $provider->get_cached( $what, $location ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | if $provider->is_cached( $what, $location ); | ||||||||||
| 70 | } | ||||||||||
| 71 | 0 | return undef; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | =head3 set_cache | ||||||||||
| 75 | |||||||||||
| 76 | $caching->set_cache( $what, $location, $value ) | ||||||||||
| 77 | |||||||||||
| 78 | =cut | ||||||||||
| 79 | |||||||||||
| 80 | 4 | ▶ | sub set_cache { | ||||||||
|
Subroutine
set_cache: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 81 | 4 | my $self = shift; | |||||||||
| 82 | 4 | my $what = shift; | |||||||||
| 83 | 4 | my $location = shift; | |||||||||
| 84 | 4 | my $value = shift; | |||||||||
| 85 | 4 | foreach my $provider ( @{ $self->providers } ) { | |||||||||
| 86 | 4 | ▶ | return $value if $provider->set_cache( $what, $location, $value ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | } | ||||||||||
| 88 | 0 | return undef; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | =head3 clear_cache | ||||||||||
| 92 | |||||||||||
| 93 | $caching->clear_cache( $what, $location ) | ||||||||||
| 94 | |||||||||||
| 95 | =cut | ||||||||||
| 96 | |||||||||||
| 97 | 6 | ▶ | sub clear_cache { | ||||||||
|
Subroutine
clear_cache: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 98 | 6 | my $self = shift; | |||||||||
| 99 | 6 | my $what = shift; | |||||||||
| 100 | 6 | my $location = shift; | |||||||||
| 101 | 6 | my $result = 0; | |||||||||
| 102 | 6 | foreach my $provider ( @{ $self->providers } ) { | |||||||||
| 103 | 6 | ▶ | $result++ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | if $provider->clear_cache( $what, $location ); | ||||||||||
| 105 | } | ||||||||||
| 106 | 6 | return $result; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | =head3 empty_cache | ||||||||||
| 110 | |||||||||||
| 111 | $caching->empty_cache( ) | ||||||||||
| 112 | |||||||||||
| 113 | =cut | ||||||||||
| 114 | |||||||||||
| 115 | 7 | ▶ | sub empty_cache { | ||||||||
|
Subroutine
empty_cache: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 116 | 7 | my $self = shift; | |||||||||
| 117 | 7 | foreach my $provider ( @{ $self->providers } ) { | |||||||||
| 118 | 7 | $provider->empty_cache(); | |||||||||
| 119 | } | ||||||||||
| 120 | 7 | return 1; | |||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | =head1 SEE ALSO | ||||||||||
| 124 | |||||||||||
| 125 | =item * L<Articulate::Caching::Native> | ||||||||||
| 126 | |||||||||||
| 127 | =item * L<Articulate::Storage> | ||||||||||
| 128 | |||||||||||
| 129 | =cut | ||||||||||
| 130 | |||||||||||
| 131 | 6 | 1; | |||||||||