| 1 | package CHI::Driver::Cache::RedisDB; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.01'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | extends 'CHI::Driver'; | |||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Cache::RedisDB; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | has 'namespace_set_key' => ( | ||||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | 2 | ▶ | default => sub { 'CHI-MANAGED-NAMESPACES' }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ); | |||||||||
| 17 | |||||||||||
| 18 | sub BUILD { | ||||||||||
| 19 | 2 | ▶ | my ($self, $params) = @_; | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||
| 20 | 2 | Cache::RedisDB->redis->sadd($self->namespace_set_key, $self->namespace); | |||||||||
| 21 | 0 | return; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | sub fetch { | ||||||||||
| 25 | 0 | ▶ | my ($self, $key) = @_; | ||||||||
|
Subroutine
fetch: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 26 | |||||||||||
| 27 | 0 | return Cache::RedisDB->get($self->namespace, $key); | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | sub store { | ||||||||||
| 31 | 0 | ▶ | my ($self, $key, $data, $expires_in) = @_; | ||||||||
|
Subroutine
store: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | my @to_set = ($self->namespace, $key, $data); | |||||||||
| 34 | 0 | ▶ | push @to_set, $expires_in if defined $expires_in; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | |||||||||||
| 36 | 0 | return Cache::RedisDB->set(@to_set); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | sub remove { | ||||||||||
| 40 | 0 | ▶ | my ($self, $key) = @_; | ||||||||
|
Subroutine
remove: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 41 | |||||||||||
| 42 | 0 | return Cache::RedisDB->del($self->namespace, $key); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | sub clear { | ||||||||||
| 46 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
clear: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 47 | |||||||||||
| 48 | 0 | my @keys = $self->get_keys; | |||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | return (@keys) ? Cache::RedisDB->del($self->namespace, @keys) : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | sub get_keys { | ||||||||||
| 54 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
get_keys: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 55 | |||||||||||
| 56 | 0 | return @{Cache::RedisDB->keys($self->namespace, '*')}; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | sub get_namespaces { | ||||||||||
| 60 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
get_namespaces: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 61 | |||||||||||
| 62 | 0 | return @{Cache::RedisDB->redis->smembers($self->namespace_set_key)}; | |||||||||
| 63 | |||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub flush_all { | ||||||||||
| 67 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
flush_all: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 68 | |||||||||||
| 69 | 0 | foreach my $ns ($self->get_namespaces) { | |||||||||
| 70 | 0 | ▶ | if (my @keys = @{Cache::RedisDB->keys($ns, '*')}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | Cache::RedisDB->del($ns, @keys); | |||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | 0 | return Cache::RedisDB->redis->del($self->namespace_set_key); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 1 | 1; | |||||||||
| 78 | __END__ | ||||||||||
| 79 | |||||||||||
| 80 | =encoding utf-8 | ||||||||||
| 81 | |||||||||||
| 82 | =head1 NAME | ||||||||||
| 83 | |||||||||||
| 84 | CHI::Driver::Cache::RedisDB - CHI Driver for Cache::RedisDB | ||||||||||
| 85 | |||||||||||
| 86 | =head1 SYNOPSIS | ||||||||||
| 87 | |||||||||||
| 88 | CHI->new(driver => 'Cache::RedisDB'); | ||||||||||
| 89 | |||||||||||
| 90 | =head1 DESCRIPTION | ||||||||||
| 91 | |||||||||||
| 92 | CHI::Driver::Cache::RedisDB is a simple wrapper around Cache::RedisDB | ||||||||||
| 93 | to provide the common CHI interface. | ||||||||||
| 94 | |||||||||||
| 95 | =head1 AUTHOR | ||||||||||
| 96 | |||||||||||
| 97 | Matt Miller E<lt>matt@inspire.comE<gt> | ||||||||||
| 98 | |||||||||||
| 99 | =head1 COPYRIGHT | ||||||||||
| 100 | |||||||||||
| 101 | Copyright 2017- Matt Miller | ||||||||||
| 102 | |||||||||||
| 103 | =head1 LICENSE | ||||||||||
| 104 | |||||||||||
| 105 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 106 | it under the same terms as Perl itself. | ||||||||||
| 107 | |||||||||||
| 108 | =head1 SEE ALSO | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||