| 1 | package Articulate::Role::Storage; | ||||||||||
| 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 | 6 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 3 | ▶ | sub get_content_cached { | ||||||||
|
Subroutine
get_content_cached: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 28 | 3 | my $self = shift; | |||||||||
| 29 | 3 | my $location = shift->location; | |||||||||
| 30 | 3 | my $caching = $self->caching; | |||||||||
| 31 | 3 | ▶ | if ( $caching->is_cached( content => $location ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | return $caching->get_cached( content => $location ); | |||||||||
| 33 | } | ||||||||||
| 34 | 3 | my $content = $self->get_content($location); | |||||||||
| 35 | 1 | $caching->set_cache( content => $location, $content ); | |||||||||
| 36 | 1 | return $content; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | =head3 get_meta_cached | ||||||||||
| 40 | |||||||||||
| 41 | $self->get_meta_cached( $location ); | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 3 | ▶ | sub get_meta_cached { | ||||||||
|
Subroutine
get_meta_cached: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 46 | 3 | my $self = shift; | |||||||||
| 47 | 3 | my $location = shift->location; | |||||||||
| 48 | 3 | my $caching = $self->caching; | |||||||||
| 49 | 3 | ▶ | if ( $caching->is_cached( meta => $location ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | return $caching->get_cached( meta => $location ); | |||||||||
| 51 | } | ||||||||||
| 52 | 3 | my $meta = $self->get_meta($location); | |||||||||
| 53 | 1 | $caching->set_cache( meta => $location, $meta ); | |||||||||
| 54 | 1 | return $meta; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 3 | ▶ | around set_content => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 3 | my ( $orig, $self ) = ( shift, shift ); | |||||||||
| 59 | 3 | my $return = $self->$orig(@_); | |||||||||
| 60 | 1 | $self->caching->set_cache( content => $_[0], $return ); | |||||||||
| 61 | 1 | return $return; | |||||||||
| 62 | 6 | }; | |||||||||
| 63 | |||||||||||
| 64 | 3 | ▶ | around set_meta => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 65 | 3 | my ( $orig, $self ) = ( shift, shift ); | |||||||||
| 66 | 3 | my $return = $self->$orig(@_); | |||||||||
| 67 | 1 | $self->caching->set_cache( meta => $_[0], $return ); | |||||||||
| 68 | 1 | return $return; | |||||||||
| 69 | 6 | }; | |||||||||
| 70 | |||||||||||
| 71 | 5 | ▶ | around delete_item => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 72 | 5 | my ( $orig, $self ) = ( shift, shift ); | |||||||||
| 73 | 5 | my $return = $self->$orig(@_); | |||||||||
| 74 | 3 | $self->caching->clear_cache( meta => $_[0] ); | |||||||||
| 75 | 3 | $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 | 3 | return $return; | |||||||||
| 83 | 6 | }; | |||||||||
| 84 | |||||||||||
| 85 | 7 | ▶ | around empty_all_content => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 86 | 7 | my ( $orig, $self ) = ( shift, shift ); | |||||||||
| 87 | 7 | my $return = $self->$orig(@_); | |||||||||
| 88 | 7 | $self->caching->empty_cache(); | |||||||||
| 89 | 7 | return $return; | |||||||||
| 90 | 6 | }; | |||||||||
| 91 | |||||||||||
| 92 | 6 | 1; | |||||||||