• Home
  • Raw
  • Download

Lines Matching +full:cache +full:- +full:to

7 Any template or component can be cached using the ``cache``
8 argument to the ``<%page>``, ``<%def>`` or ``<%block>`` directives:
17 store its content within a cache that by default is scoped
18 within memory. Subsequent calls to the template's :meth:`~.Template.render`
19 method will return content directly from the cache. When the
21 cache is garbage collected along with the template.
23 The caching system requires that a cache backend be installed; this
25 or the `dogpile.cache <http://dogpilecache.readthedocs.org>`_, as well as
26 any other third-party caching libraries that feature Mako integration.
28 By default, caching will attempt to make use of Beaker.
29 To use dogpile.cache, the
33 In addition to being available on the ``<%page>`` tag, the caching flag and all
53 Cache Arguments
56 Mako has two cache arguments available on tags that are
58 available are specific to a backend.
62 * ``cached="True"`` - enable caching for this ``<%page>``,
64 * ``cache_key`` - the "key" used to uniquely identify this content
65 in the cache. Usually, this key is chosen automatically
68 the explicit or internally-generated name when using ``<%block>``).
87 * ``cache_enabled`` - Setting this
88 to ``False`` will disable all caching functionality
89 when the template renders. Defaults to ``True``.
95 directories='/path/to/templates',
99 * ``cache_impl`` - The string name of the cache backend
100 to use. This defaults to ``'beaker'``, indicating
103 * ``cache_args`` - A dictionary of cache parameters that
104 will be consumed by the cache backend. See
108 Backend-Specific Cache Arguments
109 --------------------------------
113 Those arguments are then packaged up and passed along to the
118 * :ref:`beaker_backend` - Includes arguments understood by
120 * :ref:`dogpile.cache_backend` - Includes arguments understood by
121 dogpile.cache.
125 Using the Beaker Cache Backend
126 ------------------------------
128 When using Beaker, new implementations will want to make usage
129 of **cache regions** so that cache configurations can be maintained
130 externally to templates. These configurations live under
131 named "regions" that can be referred to within templates themselves.
134 Support for Beaker cache regions.
137 region that will store content in a memory-based dictionary,
139 where values should expire in five minutes. To configure
140 our :class:`.TemplateLookup`, first we get a handle to a
141 :class:`beaker.cache.CacheManager`:
145 from beaker.cache import CacheManager
160 directories=['/path/to/templates'],
161 module_directory='/path/to/modules',
168 Our templates can then opt to cache data in one of either region,
187 variety of arguments that can be passed to the ``cache_args``
190 and ``<%def>`` tags specific to those sections. The values
200 * ``cache_timeout`` - number of seconds in which to invalidate the
201 cached data. After this timeout, the content is re-generated
204 * ``cache_type`` - type of caching. ``'memory'``, ``'file'``, ``'dbm'``, or
206 also accepted by the dogpile.cache Mako plugin, though not by Beaker itself).
208 * ``cache_url`` - (only used for ``memcached`` but required) a single
209 IP address or a semi-colon separated list of IP address of
210 memcache servers to use. Available as ``url`` in the ``cache_args``
212 * ``cache_dir`` - in the case of the ``'file'`` and ``'dbm'`` cache types,
213 this is the filesystem directory with which to store data
222 Using the dogpile.cache Backend
223 -------------------------------
225 `dogpile.cache`_ is a new replacement for Beaker. It provides
226 a modernized, slimmed down interface and is generally easier to use
227 than Beaker. As of this writing it has not yet been released. dogpile.cache
228 includes its own Mako cache plugin -- see :mod:`dogpile.cache.plugins.mako_cache` in the
229 dogpile.cache documentation.
231 Programmatic Cache Access
234 The :class:`.Template`, as well as any template-derived :class:`.Namespace`, has
235 an accessor called ``cache`` which returns the :class:`.Cache` object
238 capabilities, such as the ability to get and put arbitrary
244 local.cache.set("somekey", type="memory", "somevalue")
247 Above, the cache associated with the ``local`` namespace is
248 accessed and a key is placed within a memory cache.
250 More commonly, the ``cache`` object is used to invalidate cached
258 template.cache.invalidate_body()
261 template.cache.invalidate_def('somedef')
264 template.cache.invalidate('somekey')
267 itself using the :attr:`impl <.Cache.impl>` attribute:
271 template.cache.impl.do_something_special()
273 Note that using implementation-specific methods will mean you can't
279 Cache Plugins
284 the rudimental methods Mako needs to implement the caching
285 API. Mako includes the :class:`.BeakerCacheImpl` class to
288 the name given as the ``cache_impl`` argument to :class:`.Template`
291 the `EntryPoint` group named ``"mako.cache"``. It can also be
295 An example plugin that implements a local dictionary cache:
299 from mako.cache import Cacheimpl, register_plugin
302 def __init__(self, cache):
303 super(SimpleCacheImpl, self).__init__(cache)
322 # optional - register the class locally
333 Guidelines for Writing Cache Plugins
334 ------------------------------------
336 * The :class:`.CacheImpl` is created on a per-:class:`.Template` basis. The
338 persisted or returned by the cache methods. The actual :class:`.Template`
339 is available via the ``self.cache.template`` attribute. The ``self.cache.id``
341 a good value to use in order to represent a unique namespace of keys specific
342 to the template.
346 only used in response to direct programmatic access to the corresponding
347 methods on the :class:`.Cache` object.
350 to ensure caching implementations are threadsafe.
352 is a minimal locking system derived from Beaker, can be used to help
357 * All arguments passed to ``**kw`` come directly from the parameters
360 the argument ``cache_timeout``, which is passed to the plugin
361 as the name ``timeout`` with the value converted to an integer.
366 be acquired using the accessor ``self.cache.template.module_directory``.
367 This directory can be a good place to throw cache-related work
374 .. autoclass:: mako.cache.Cache
376 :show-inheritance:
378 .. autoclass:: mako.cache.CacheImpl
380 :show-inheritance:
382 .. autofunction:: mako.cache.register_plugin
386 :show-inheritance: