| 1 | # | ||||||||||
| 2 | # This file is part of Jedi-Plugin-Session | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is copyright (c) 2013 by celogeek <me@celogeek.com>. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||
| 8 | # | ||||||||||
| 9 | package Jedi::Plugin::Session::Backend::Memory; | ||||||||||
| 10 | |||||||||||
| 11 | # ABSTRACT: Backend storage for Memory | ||||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 3 | our $VERSION = '0.05'; # VERSION | |||||||||
| 16 | 3 | ▶ | use Time::Duration::Parse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 3 | ▶ | use Cache::LRU::WithExpires; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 3 | has '_cache' => ( is => 'lazy' ); | |||||||||
| 21 | |||||||||||
| 22 | 2 | ▶ | sub _build__cache { | ||||||||
|
Subroutine
_build__cache: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 2 | return Cache::LRU::WithExpires->new; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | has 'expires_in' => ( | ||||||||||
| 27 | is => 'ro', | ||||||||||
| 28 | 0 | ▶ | default => sub { 3 * 3600 }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | 2 | ▶ | coerce => sub { parse_duration( $_[0] ) } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 3 | ); | |||||||||
| 31 | |||||||||||
| 32 | ## no critic (NamingConventions::ProhibitAmbiguousNames) | ||||||||||
| 33 | 9 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 34 | 9 | my ( $self, $uuid ) = @_; | |||||||||
| 35 | 9 | ▶ | return if !defined $uuid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | 9 | return $self->_cache->get($uuid); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 4 | ▶ | sub set { | ||||||||
|
Subroutine
set: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 41 | 4 | my ( $self, $uuid, $value ) = @_; | |||||||||
| 42 | 4 | ▶ | return if !defined $uuid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 4 | $self->_cache->set( $uuid, $value, $self->expires_in ); | |||||||||
| 44 | 4 | return 1; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 3 | 1; | |||||||||
| 48 | |||||||||||
| 49 | __END__ | ||||||||||