<s> from mako import compat , util <EOL> _cache_plugins = util . PluginLoader ( "<STR_LIT>" ) <EOL> register_plugin = _cache_plugins . register <EOL> register_plugin ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> class Cache ( object ) : <EOL> """<STR_LIT>""" <EOL> impl = None <EOL> """<STR_LIT>""" <EOL> id = None <EOL> """<STR_LIT>""" <EOL> starttime = None <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , template , * args ) : <EOL> if isinstance ( template , compat . string_types ) and args : <EOL> return <EOL> self . template = template <EOL> self . id = template . module . __name__ <EOL> self . starttime = template . module . _modified_time <EOL> self . _def_regions = { } <EOL> self . impl = self . _load_impl ( self . template . cache_impl ) <EOL> def _load_impl ( self , name ) : <EOL> return _cache_plugins . load ( name ) ( self ) <EOL> def get_or_create ( self , key , creation_function , ** kw ) : <EOL> """<STR_LIT>""" <EOL> return self . _ctx_get_or_create ( key , creation_function , None , ** kw ) <EOL> def _ctx_get_or_create ( self , key , creation_function , context , ** kw ) : <EOL> """<STR_LIT>""" <EOL> if not self . template . cache_enabled : <EOL> return creation_function ( ) <EOL> return self . impl . get_or_create ( key , <EOL> creation_function , <EOL> ** self . _get_cache_kw ( kw , context ) ) <EOL> def set ( self , key , value , ** kw ) : <EOL> """<STR_LIT>""" <EOL> self . impl . set ( key , value , ** self . _get_cache_kw ( kw , None ) ) <EOL> put = set <EOL> """<STR_LIT>""" <EOL> def get ( self , key , ** kw ) : <EOL> """<STR_LIT>""" <EOL> return self . impl . get ( key , ** self . _get_cache_kw ( kw , None ) ) <EOL> def invalidate ( self , key , ** kw ) : <EOL> """<STR_LIT>""" <EOL> self . impl . invalidate ( key , ** self . _get_cache_kw ( kw , None ) ) <EOL> def invalidate_body ( self ) : <EOL> """<STR_LIT>""" <EOL> self . invalidate ( '<STR_LIT>' , __M_defname = '<STR_LIT>' ) <EOL> def invalidate_def ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . invalidate ( '<STR_LIT>' % name , __M_defname = '<STR_LIT>' % name ) <EOL> def invalidate_closure ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . invalidate ( name , __M_defname = name ) <EOL> def _get_cache_kw ( self , kw , context ) : <EOL> defname = kw . pop ( '<STR_LIT>' , None ) <EOL> if not defname : <EOL> tmpl_kw = self . template . cache_args . copy ( ) <EOL> tmpl_kw . update ( kw ) <EOL> elif defname in self . _def_regions : <EOL> tmpl_kw = self . _def_regions [ defname ] <EOL> else : <EOL> tmpl_kw = self . template . cache_args . copy ( ) <EOL> tmpl_kw . update ( kw ) <EOL> self . _def_regions [ defname ] = tmpl_kw <EOL> if context and self . impl . pass_context : <EOL> tmpl_kw = tmpl_kw . copy ( ) <EOL> tmpl_kw . setdefault ( '<STR_LIT>' , context ) <EOL> return tmpl_kw <EOL> class CacheImpl ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cache ) : <EOL> self . cache = cache <EOL> pass_context = False <EOL> """<STR_LIT>""" <EOL> def get_or_create ( self , key , creation_function , ** kw ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def set ( self , key , value , ** kw ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def get ( self , key , ** kw ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def invalidate ( self , key , ** kw ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) </s>
