| 1 | package DTL::Fast::Cache::Memcached; | ||
| 2 | use strict; use warnings FATAL => 'all'; | ||
| 3 | use parent 'DTL::Fast::Cache::Runtime'; | ||
| 4 | |||
| 5 | our %SUPPORTS = qw( | ||
| 6 | Cache::Memcached 1 | ||
| 7 | Cache::Memcached::Fast 1 | ||
| 8 | ); | ||
| 9 | |||
| 10 | #@Override | ||
| 11 | sub new | ||
| 12 | { | ||
| 13 | my( $proto, $memcached ) = @_; | ||
| 14 | |||
| 15 | if( not exists $SUPPORTS{ref $memcached} ) | ||
| 16 | { | ||
| 17 | die sprintf( | ||
| 18 | "You may construct %s object using one of the following modules:\n\t%s\n" | ||
| 19 | , $proto // 'undef' | ||
| 20 | , join( "\n\t", keys %SUPPORTS ) | ||
| 21 | ); | ||
| 22 | } | ||
| 23 | |||
| 24 | return $proto->SUPER::new( 'mc' => $memcached ); | ||
| 25 | |||
| 26 | } | ||
| 27 | |||
| 28 | #@Override | ||
| 29 | sub read_data | ||
| 30 | { | ||
| 31 | my( $self, $key ) = @_; | ||
| 32 | return $self->{'mc'}->get($key); | ||
| 33 | } | ||
| 34 | |||
| 35 | #@Override | ||
| 36 | sub write_data{ | ||
| 37 | my( $self, $key, $data ) = @_; | ||
| 38 | |||
| 39 | return $self->{'mc'}->set($key, $data); | ||
| 40 | } | ||
| 41 | |||
| 42 | 1; |