<s> from threading import local <EOL> from django . core . cache . backends import memcached <EOL> from cachebot . logger import CacheLogDecorator <EOL> @ CacheLogDecorator <EOL> class BaseMemcachedCache ( memcached . BaseMemcachedCache ) : <EOL> def _get_memcache_timeout ( self , timeout ) : <EOL> if timeout is None : <EOL> timeout = self . default_timeout <EOL> return timeout <EOL> def append ( self , key , value , version = None ) : <EOL> key = self . make_key ( key , version = version ) <EOL> self . _cache . append ( key , value ) <EOL> def prepend ( self , key , value , version = None ) : <EOL> key = self . make_key ( key , version = version ) <EOL> self . _cache . prepend ( key , value ) <EOL> def smart_incr ( self , key , delta = <NUM_LIT:1> , default = <NUM_LIT:0> , ** kwargs ) : <EOL> try : <EOL> return self . incr ( key , delta = <NUM_LIT:1> ) <EOL> except ValueError : <EOL> val = default + delta <EOL> self . add ( key , val , ** kwargs ) <EOL> return val <EOL> def smart_decr ( self , key , delta = <NUM_LIT:1> , default = <NUM_LIT:0> , ** kwargs ) : <EOL> try : <EOL> return self . incr ( key , delta = <NUM_LIT:1> ) <EOL> except ValueError : <EOL> val = default - delta <EOL> self . add ( key , val , ** kwargs ) <EOL> return val <EOL> def replace ( self , key , value , timeout = <NUM_LIT:0> , version = None ) : <EOL> key = self . make_key ( key , version = version ) <EOL> return self . _cache . replace ( key , value , self . _get_memcache_timeout ( timeout ) ) <EOL> class MemcachedCache ( BaseMemcachedCache ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , server , params ) : <EOL> import memcache <EOL> super ( MemcachedCache , self ) . __init__ ( server , params , <EOL> library = memcache , <EOL> value_not_found_exception = ValueError ) <EOL> class PyLibMCCache ( BaseMemcachedCache ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , server , params ) : <EOL> import pylibmc <EOL> self . _local = local ( ) <EOL> super ( PyLibMCCache , self ) . __init__ ( server , params , <EOL> library = pylibmc , <EOL> value_not_found_exception = pylibmc . NotFound ) <EOL> @ property <EOL> def _cache ( self ) : <EOL> client = getattr ( self . _local , '<STR_LIT>' , None ) <EOL> if client : <EOL> return client <EOL> client = self . _lib . Client ( self . _servers ) <EOL> if self . _options : <EOL> client . behaviors = self . _options <EOL> self . _local . client = client <EOL> return client </s>
