| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Auth::Kokolores::Plugin::CacheMemcached; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 718 | use Moose; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | # ABSTRACT: a memcached based cache for kokolores | 
| 6 |  |  |  |  |  |  | our $VERSION = '1.01'; # VERSION | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | extends 'Auth::Kokolores::Plugin'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 1 |  |  | 1 |  | 3960 | use Auth::Kokolores::ConnectionPool; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 222 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | has 'handle' => ( is => 'rw', isa => 'Str', default => 'memcached' ); | 
| 14 |  |  |  |  |  |  | has 'ttl' => ( is => 'rw', isa => 'Int', default => 300 ); | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | has 'cache_negative' => ( is => 'rw', isa => 'Bool', default => 0 ); | 
| 17 |  |  |  |  |  |  | has 'ttl_negative' => ( is => 'rw', isa => 'Int', lazy => 1, | 
| 18 |  |  |  |  |  |  | default => sub { shift->ttl; } | 
| 19 |  |  |  |  |  |  | ); | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | has 'memcached' => ( | 
| 22 |  |  |  |  |  |  | is => 'ro', isa => 'Cache::Memcached', | 
| 23 |  |  |  |  |  |  | lazy => 1, | 
| 24 |  |  |  |  |  |  | default => sub { | 
| 25 |  |  |  |  |  |  | my $self = shift; | 
| 26 |  |  |  |  |  |  | return Auth::Kokolores::ConnectionPool->get_handle( | 
| 27 |  |  |  |  |  |  | $self->handle, | 
| 28 |  |  |  |  |  |  | ); | 
| 29 |  |  |  |  |  |  | }, | 
| 30 |  |  |  |  |  |  | ); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub pre_process { | 
| 33 | 0 |  |  | 0 | 0 |  | my ( $self, $r ) = @_; | 
| 34 | 0 |  |  |  |  |  | my $cache = $self->memcached->get( $r->fingerprint ); | 
| 35 | 0 | 0 |  |  |  |  | if( defined $cache ) { | 
| 36 | 0 |  |  |  |  |  | $r->log(4, 'found cached entry for '.$r->fingerprint); | 
| 37 | 0 |  |  |  |  |  | return $cache; | 
| 38 |  |  |  |  |  |  | } | 
| 39 | 0 |  |  |  |  |  | $r->log(4, 'cache miss for '.$r->fingerprint); | 
| 40 | 0 |  |  |  |  |  | return; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | sub post_process { | 
| 44 | 0 |  |  | 0 | 0 |  | my ( $self, $r, $response ) = @_; | 
| 45 | 0 | 0 | 0 |  |  |  | if( $response->success || $self->cache_negative ) { | 
| 46 | 0 | 0 |  |  |  |  | my $ttl = $response->success ? $self->ttl : $self->ttl_negative; | 
| 47 | 0 |  |  |  |  |  | $r->log(4, 'adding to cache '.$r->fingerprint.' (ttl '.$ttl.')'); | 
| 48 | 0 |  |  |  |  |  | $self->memcached->set( $r->fingerprint, $response, $ttl ); | 
| 49 |  |  |  |  |  |  | } | 
| 50 | 0 |  |  |  |  |  | return; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | 1; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | __END__ | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | =pod | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =encoding UTF-8 | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head1 NAME | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | Auth::Kokolores::Plugin::CacheMemcached - a memcached based cache for kokolores | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head1 VERSION | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | version 1.01 | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | This plugin caches authentication requests in memcached. | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head1 USAGE | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | <Plugin memcache> | 
| 76 |  |  |  |  |  |  | module = "MemcachedConnection" | 
| 77 |  |  |  |  |  |  | servers = "127.0.0.1:11211" | 
| 78 |  |  |  |  |  |  | namespace = "auth-" | 
| 79 |  |  |  |  |  |  | </Plugin> | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | <Plugin auth-cache> | 
| 82 |  |  |  |  |  |  | module="CacheMemcached" | 
| 83 |  |  |  |  |  |  | ttl="300" | 
| 84 |  |  |  |  |  |  | </Plugin> | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =head1 AUTHOR | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | Markus Benning <ich@markusbenning.de> | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | This software is Copyright (c) 2016 by Markus Benning <ich@markusbenning.de>. | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | This is free software, licensed under: | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | The GNU General Public License, Version 2, June 1991 | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =cut |