U  e@sHddlmZedZejZedddGdddZGdd d Zd S) )utilz mako.cacheZbeakerzmako.ext.beaker_cacheZBeakerCacheImplc@sxeZdZdZdZdZdZddZddZddZ d d Z d d Z e Z d dZ ddZddZddZddZddZdS)CacheaRepresents a data content cache made available to the module space of a specific :class:`.Template` object. .. versionadded:: 0.6 :class:`.Cache` by itself is mostly a container for a :class:`.CacheImpl` object, which implements a fixed API to provide caching services; specific subclasses exist to implement different caching strategies. Mako includes a backend that works with the Beaker caching system. Beaker itself then supports a number of backends (i.e. file, memory, memcached, etc.) The construction of a :class:`.Cache` is part of the mechanics of a :class:`.Template`, and programmatic access to this cache is typically via the :attr:`.Template.cache` attribute. NcGsFt|tr|rdS||_|jj|_|jj|_i|_| |jj |_ dSN) isinstancestrtemplatemodule__name__idZ_modified_time starttime _def_regions _load_implZ cache_implimpl)selfrargsr8/opt/hc_python/lib/python3.8/site-packages/mako/cache.py__init__As  zCache.__init__cCst||Sr)_cache_pluginsloadrnamerrrr LszCache._load_implcKs|j||df|S)cRetrieve a value from the cache, using the given creation function to generate a new value.N)_ctx_get_or_createrkeycreation_functionkwrrr get_or_createOszCache.get_or_createcKs(|jjs|S|jj||f|||S)r)rZ cache_enabledrr _get_cache_kw)rrrcontextrrrrrUs zCache._ctx_get_or_createcKs|jj||f||ddSzPlace a value in the cache. :param key: the value's key. :param value: the value. :param \**kw: cache configuration arguments. N)rsetrrrvaluerrrrr"`s z Cache.setcKs|jj|f||dS)aFRetrieve a value from the cache. :param key: the value's key. :param \**kw: cache configuration arguments. The backend is configured using these arguments upon first request. Subsequent requests that use the same series of configuration values will use that same backend. N)rgetrrrrrrrr%rs z Cache.getcKs|jj|f||ddS)aFInvalidate a value in the cache. :param key: the value's key. :param \**kw: cache configuration arguments. The backend is configured using these arguments upon first request. Subsequent requests that use the same series of configuration values will use that same backend. N)r invalidaterr&rrrr'~s zCache.invalidatecCs|jddddS)zWInvalidate the cached content of the "body" method for this template. Z render_body __M_defnameNr')rrrrinvalidate_bodyszCache.invalidate_bodycCs|jd|d|ddS)z`Invalidate the cached content of a particular ``<%def>`` within this template. z render_%sr(Nr*rrrrinvalidate_defszCache.invalidate_defcCs|j||ddS)aNInvalidate a nested ``<%def>`` within this template. Caching of nested defs is a blunt tool as there is no management of scope -- nested defs that use cache tags need to have names unique of all other nested defs in the template, else their content will be overwritten by each other. r(Nr*rrrrinvalidate_closures zCache.invalidate_closurecCs|dd}|s(|jj}||n6||jkr>|j|}n |jj}||||j|<|r~|jjr~|}|d||S)Nr)r ) poprZ cache_argscopyupdater r pass_context setdefault)rrr ZdefnameZtmpl_kwrrrrs          zCache._get_cache_kw)r __module__ __qualname____doc__rr r rr rrr"putr%r'r+r,r-rrrrrrs         rc@s<eZdZdZddZdZddZddZd d Zd d Z d S) CacheImplz:Provide a cache implementation for use by :class:`.Cache`.cCs ||_dSr)cache)rr8rrrrszCacheImpl.__init__FcKs tdS)a7Retrieve a value from the cache, using the given creation function to generate a new value. This function *must* return a value, either from the cache, or via the given creation function. If the creation function is called, the newly created value should be populated into the cache under the given key before being returned. :param key: the value's key. :param creation_function: function that when called generates a new value. :param \**kw: cache configuration arguments. NNotImplementedErrorrrrrrszCacheImpl.get_or_createcKs tdSr!r9r#rrrr"sz CacheImpl.setcKs tdS)zRetrieve a value from the cache. :param key: the value's key. :param \**kw: cache configuration arguments. Nr9r&rrrr%sz CacheImpl.getcKs tdS)zInvalidate a value in the cache. :param key: the value's key. :param \**kw: cache configuration arguments. Nr9r&rrrr'szCacheImpl.invalidateN) r r3r4r5rr1rr"r%r'rrrrr7s  r7N)makorZ PluginLoaderrregisterZregister_pluginrr7rrrrs   )