<s> "<STR_LIT>" <EOL> from django . core . cache . backends . base import BaseCache <EOL> import time <EOL> class CacheClass ( BaseCache ) : <EOL> def __init__ ( self , host , params ) : <EOL> BaseCache . __init__ ( self , params ) <EOL> self . _cache = { } <EOL> self . _expire_info = { } <EOL> max_entries = params . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> try : <EOL> self . _max_entries = int ( max_entries ) <EOL> except ( ValueError , TypeError ) : <EOL> self . _max_entries = <NUM_LIT> <EOL> cull_frequency = params . get ( '<STR_LIT>' , <NUM_LIT:3> ) <EOL> try : <EOL> self . _cull_frequency = int ( cull_frequency ) <EOL> except ( ValueError , TypeError ) : <EOL> self . _cull_frequency = <NUM_LIT:3> <EOL> def get ( self , key , default = None ) : <EOL> now = time . time ( ) <EOL> exp = self . _expire_info . get ( key ) <EOL> if exp is None : <EOL> return default <EOL> elif exp < now : <EOL> del self . _cache [ key ] <EOL> del self . _expire_info [ key ] <EOL> return default <EOL> else : <EOL> return self . _cache [ key ] <EOL> def set ( self , key , value , timeout = None ) : <EOL> if len ( self . _cache ) >= self . _max_entries : <EOL> self . _cull ( ) <EOL> if timeout is None : <EOL> timeout = self . default_timeout <EOL> self . _cache [ key ] = value <EOL> self . _expire_info [ key ] = time . time ( ) + timeout <EOL> def delete ( self , key ) : <EOL> try : <EOL> del self . _cache [ key ] <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> del self . _expire_info [ key ] <EOL> except KeyError : <EOL> pass <EOL> def has_key ( self , key ) : <EOL> return self . _cache . has_key ( key ) <EOL> def _cull ( self ) : <EOL> if self . _cull_frequency == <NUM_LIT:0> : <EOL> self . _cache . clear ( ) <EOL> self . _expire_info . clear ( ) <EOL> else : <EOL> doomed = [ k for ( i , k ) in enumerate ( self . _cache ) if i % self . _cull_frequency == <NUM_LIT:0> ] <EOL> for k in doomed : <EOL> self . delete ( k ) </s>
