| 1 | package CHI::Driver::Metacache; | ||
| 2 | 20 | $CHI::Driver::Metacache::VERSION = '0.59'; | |
| 3 | 20 | ▶ | use CHI::Constants qw(CHI_Meta_Namespace); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 20 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 20 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 20 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 20 | has 'meta_cache' => ( is => 'lazy', clearer => 'clear_meta_cache', predicate => 'has_meta_cache' ); | |
| 9 | 20 | has 'owner_cache' => ( is => 'ro', weak_ref => 1 ); | |
| 10 | 20 | has 'owner_namespace' => ( is => 'lazy', clearer => 'clear_owner_namespace', predicate => 'has_owner_namespace' ); | |
| 11 | |||
| 12 | sub _build_meta_cache { | ||
| 13 | 85 | ▶ | my ($self) = @_; |
|
Subroutine
_build_meta_cache: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | 85 | my $owner_cache = $self->owner_cache; | |
| 16 | 85 | my %params = %{ $owner_cache->constructor_params }; | |
| 17 | 85 | delete( @params{qw(l1_cache mirror_cache parent_cache chi_root_class)} ); | |
| 18 | 85 | $params{label} = $owner_cache->label . " (meta)"; | |
| 19 | 85 | $params{namespace} = CHI_Meta_Namespace; | |
| 20 | 85 | return $owner_cache->chi_root_class->new(%params); | |
| 21 | } | ||
| 22 | |||
| 23 | sub _build_owner_namespace { | ||
| 24 | 85 | ▶ | my ($self) = @_; |
|
Subroutine
_build_owner_namespace: called CC=1 SCAR=0.0
| |||
| 25 | |||
| 26 | 85 | return $self->owner_cache->namespace; | |
| 27 | } | ||
| 28 | |||
| 29 | sub get { | ||
| 30 | 2291 | ▶ | my ( $self, $key ) = @_; |
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 31 | |||
| 32 | 2291 | return $self->meta_cache->fetch( $self->_prefixed_key($key) ); | |
| 33 | } | ||
| 34 | |||
| 35 | sub set { | ||
| 36 | 1809 | ▶ | my ( $self, $key, $value ) = @_; |
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 37 | |||
| 38 | 1809 | return $self->meta_cache->store( $self->_prefixed_key($key), $value ); | |
| 39 | } | ||
| 40 | |||
| 41 | sub remove { | ||
| 42 | 0 | ▶ | my ( $self, $key, $value ) = @_; |
|
Subroutine
remove: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 43 | |||
| 44 | 0 | return $self->meta_cache->remove( $self->_prefixed_key($key) ); | |
| 45 | } | ||
| 46 | |||
| 47 | sub _prefixed_key { | ||
| 48 | 4100 | ▶ | my ( $self, $key ) = @_; |
|
Subroutine
_prefixed_key: called CC=1 SCAR=0.0
| |||
| 49 | |||
| 50 | 4100 | return $self->owner_namespace . ":" . $key; | |
| 51 | } | ||
| 52 | |||
| 53 | 20 | 1; | |
| 54 | |||
| 55 | __END__ | ||