Skip to content
Snippets Groups Projects
Commit 89859132 authored by Mike Bayer's avatar Mike Bayer
Browse files

- caching now uses beaker.cache_manager directly. For best results

use Beaker 1.0.4, just checked in.   This version of Beaker stores
no persistent state in memory for each key, allowing dynamically
generated keys to work without using up available memory.
parent 64eb9262
No related branches found
Tags rel_0_2_1
No related merge requests found
0.2.3 0.2.3
- added support for Jython 2.5. - added support for Jython 2.5.
- cache module now uses Beaker's clsmap to get at - cache module now uses Beaker's CacheManager
container classes, so cache types such as object directly, so that all cache types are included.
"ext:google", "ext:sqla", etc. are available. memcached is available as both "ext:memcached" and
memcached is available as both "ext:memcached" and "memcached", the latter for backwards compatibility.
"memcached", the latter for backwards compatibility.
This requires Beaker>=1.0.1.
- added "cache" accessor to Template, Namespace. - added "cache" accessor to Template, Namespace.
e.g. ${local.cache.get('somekey')} or e.g. ${local.cache.get('somekey')} or
...@@ -19,16 +17,23 @@ This requires Beaker>=1.0.1. ...@@ -19,16 +17,23 @@ This requires Beaker>=1.0.1.
(i.e. storage type) are derived from whatever has (i.e. storage type) are derived from whatever has
been already persisted for that template. been already persisted for that template.
[ticket:92] [ticket:92]
- For cache changes to work fully, Beaker 1.0.4 is required.
1.0.1 and up will work as well with the exception of
cache expiry. Note that Beaker 1.0.4 is **required**
for applications which use dynamically generated keys,
since previous versions will permanently store state in memory
for each individual key and thus use up all available memory.
- fixed the html_error_template not handling tracebacks from - fixed the html_error_template not handling tracebacks from
normal .py files with a magic encoding comment [ticket:88] normal .py files with a magic encoding comment [ticket:88]
- added ModuleTemplate class, which allows the construction - added ModuleTemplate class, which allows the construction
of a Template given a Python module generated by a previous of a Template given a Python module generated by a previous
Template. This allows Python modules alone to be used Template. This allows Python modules alone to be used
as templates with no compilation step. Source code as templates with no compilation step. Source code
and template source are optional but allow error reporting and template source are optional but allow error reporting
to work correctly. to work correctly.
- fixed Python 2.3 compat. in mako.pyparser [ticket:90] - fixed Python 2.3 compat. in mako.pyparser [ticket:90]
......
from mako import exceptions from mako import exceptions
try: try:
from beaker import container, exceptions, cache from beaker import cache
clsmap = cache.clsmap cache = cache.CacheManager()
if 'ext:memcached' in clsmap:
clsmap['memcached'] = clsmap['ext:memcached']
except ImportError: except ImportError:
container = None cache = None
clsmap = {}
class Cache(object): class Cache(object):
def __init__(self, id, starttime): def __init__(self, id, starttime):
self.id = id self.id = id
self.starttime = starttime self.starttime = starttime
if container is not None:
self.context = container.ContainerContext()
self.def_regions = {} self.def_regions = {}
def put(self, key, value, **kwargs): def put(self, key, value, **kwargs):
c = self._get_container(key, **kwargs) defname = kwargs.pop('defname', None)
if not c: expiretime = kwargs.pop('expiretime', None)
raise exceptions.RuntimeException("No cache container exists for key %r" % key) createfunc = kwargs.pop('createfunc', None)
c.set_value(value)
self._get_cache(defname, **kwargs).put_value(key, starttime=self.starttime, expiretime=expiretime)
def get(self, key, **kwargs): def get(self, key, **kwargs):
c = self._get_container(key, **kwargs) defname = kwargs.pop('defname', None)
if c: expiretime = kwargs.pop('expiretime', None)
return c.get_value() createfunc = kwargs.pop('createfunc', None)
else:
return None
def invalidate(self, key, defname, **kwargs): return self._get_cache(defname, **kwargs).get_value(key, starttime=self.starttime, expiretime=expiretime, createfunc=createfunc)
c = self._get_container(key, defname, **kwargs)
if c: def invalidate(self, key, **kwargs):
c.clear_value() defname = kwargs.pop('defname', None)
expiretime = kwargs.pop('expiretime', None)
createfunc = kwargs.pop('createfunc', None)
self._get_cache(defname, **kwargs).remove_value(key, starttime=self.starttime, expiretime=expiretime)
def invalidate_body(self): def invalidate_body(self):
self.invalidate('render_body', 'render_body') self.invalidate('render_body', defname='render_body')
def invalidate_def(self, name): def invalidate_def(self, name):
self.invalidate('render_%s' % name, 'render_%s' % name) self.invalidate('render_%s' % name, defname='render_%s' % name)
def invalidate_closure(self, name): def invalidate_closure(self, name):
self.invalidate(name, name) self.invalidate(name, defname=name)
def _get_container(self, key, defname, **kwargs): def _get_cache(self, defname, type=None, **kw):
if not container: if not cache:
raise exceptions.RuntimeException("the Beaker package is required to use cache functionality.") raise exceptions.RuntimeException("the Beaker package is required to use cache functionality.")
if type == 'memcached':
type = kwargs.pop('type', None) type = 'ext:memcached'
if not type: if not type:
type = self.def_regions.get(defname, 'memory') (type, kw) = self.def_regions.get(defname, ('memory', {}))
else: else:
self.def_regions[defname] = type self.def_regions[defname] = (type, kw)
return cache.get_cache(self.id, type=type, **kw)
return container.Value(key, self.context, self.id, clsmap[type], starttime=self.starttime, **kwargs)
\ No newline at end of file
...@@ -37,7 +37,7 @@ SVN version: ...@@ -37,7 +37,7 @@ SVN version:
scripts=['scripts/mako-render'], scripts=['scripts/mako-render'],
zip_safe=False, zip_safe=False,
install_requires=[ install_requires=[
'Beaker>=1.0.1', 'Beaker>=1.0.4',
], ],
entry_points=""" entry_points="""
[python.templating.engines] [python.templating.engines]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment