| 1 | package WebService::GrowthBook::InMemoryFeatureCache; | ||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 7 | ▶ | no indirect; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use feature qw(state); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 7 | ▶ | use Object::Pad; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 7 | ▶ | use WebService::GrowthBook::CacheEntry; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 7 | our $VERSION = '0.003'; ## VERSION | |||||||||
| 10 | |||||||||||
| 11 | 7 | ▶ | class WebService::GrowthBook::InMemoryFeatureCache :isa(WebService::GrowthBook::AbstractFeatureCache) { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 7 | field %cache; | |||||||||
| 13 | |||||||||||
| 14 | 12 | ▶ | method get($key){ | ||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 15 | 12 | my $entry = $cache{$key}; | |||||||||
| 16 | 12 | ▶ | return undef unless $entry; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 4 | ▶ | return $entry->value if !$entry->expired; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 1 | return undef; | |||||||||
| 19 | 7 | } | |||||||||
| 20 | |||||||||||
| 21 | 4 | ▶ | method set($key, $value, $ttl){ | ||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 22 | 4 | ▶ | if(exists $cache{$key}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1 | $cache{$key}->update($value); | |||||||||
| 24 | 1 | return; | |||||||||
| 25 | } | ||||||||||
| 26 | 3 | $cache{$key} = WebService::GrowthBook::CacheEntry->new(value => $value, ttl => $ttl); | |||||||||
| 27 | 7 | } | |||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | method clear(){ | ||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | 1 | %cache = (); | |||||||||
| 31 | 7 | } | |||||||||
| 32 | |||||||||||
| 33 | 104 | ▶ | sub singleton($class){ | ||||||||
|
Subroutine
singleton: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | 104 | state $instance = $class->new(); | |||||||||
| 35 | 104 | return $instance; | |||||||||
| 36 | } | ||||||||||
| 37 | 7 | } | |||||||||