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
No related tags found
No related merge requests found
0.2.3
- added support for Jython 2.5.
- cache module now uses Beaker's clsmap to get at
container classes, so cache types such as
"ext:google", "ext:sqla", etc. are available.
memcached is available as both "ext:memcached" and
"memcached", the latter for backwards compatibility.
This requires Beaker>=1.0.1.
- cache module now uses Beaker's CacheManager
object directly, so that all cache types are included.
memcached is available as both "ext:memcached" and
"memcached", the latter for backwards compatibility.
- added "cache" accessor to Template, Namespace.
e.g. ${local.cache.get('somekey')} or
......@@ -19,16 +17,23 @@ This requires Beaker>=1.0.1.
(i.e. storage type) are derived from whatever has
been already persisted for that template.
[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
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
of a Template given a Python module generated by a previous
Template. This allows Python modules alone to be used
as templates with no compilation step. Source code
and template source are optional but allow error reporting
to work correctly.
of a Template given a Python module generated by a previous
Template. This allows Python modules alone to be used
as templates with no compilation step. Source code
and template source are optional but allow error reporting
to work correctly.
- fixed Python 2.3 compat. in mako.pyparser [ticket:90]
......
from mako import exceptions
try:
from beaker import container, exceptions, cache
clsmap = cache.clsmap
if 'ext:memcached' in clsmap:
clsmap['memcached'] = clsmap['ext:memcached']
from beaker import cache
cache = cache.CacheManager()
except ImportError:
container = None
clsmap = {}
cache = None
class Cache(object):
def __init__(self, id, starttime):
self.id = id
self.starttime = starttime
if container is not None:
self.context = container.ContainerContext()
self.def_regions = {}
def put(self, key, value, **kwargs):
c = self._get_container(key, **kwargs)
if not c:
raise exceptions.RuntimeException("No cache container exists for key %r" % key)
c.set_value(value)
defname = kwargs.pop('defname', None)
expiretime = kwargs.pop('expiretime', None)
createfunc = kwargs.pop('createfunc', None)
self._get_cache(defname, **kwargs).put_value(key, starttime=self.starttime, expiretime=expiretime)
def get(self, key, **kwargs):
c = self._get_container(key, **kwargs)
if c:
return c.get_value()
else:
return None
defname = kwargs.pop('defname', None)
expiretime = kwargs.pop('expiretime', None)
createfunc = kwargs.pop('createfunc', None)
def invalidate(self, key, defname, **kwargs):
c = self._get_container(key, defname, **kwargs)
if c:
c.clear_value()
return self._get_cache(defname, **kwargs).get_value(key, starttime=self.starttime, expiretime=expiretime, createfunc=createfunc)
def invalidate(self, key, **kwargs):
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):
self.invalidate('render_body', 'render_body')
self.invalidate('render_body', defname='render_body')
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):
self.invalidate(name, name)
def _get_container(self, key, defname, **kwargs):
if not container:
self.invalidate(name, defname=name)
def _get_cache(self, defname, type=None, **kw):
if not cache:
raise exceptions.RuntimeException("the Beaker package is required to use cache functionality.")
type = kwargs.pop('type', None)
if type == 'memcached':
type = 'ext:memcached'
if not type:
type = self.def_regions.get(defname, 'memory')
(type, kw) = self.def_regions.get(defname, ('memory', {}))
else:
self.def_regions[defname] = type
return container.Value(key, self.context, self.id, clsmap[type], starttime=self.starttime, **kwargs)
self.def_regions[defname] = (type, kw)
return cache.get_cache(self.id, type=type, **kw)
\ No newline at end of file
......@@ -37,7 +37,7 @@ SVN version:
scripts=['scripts/mako-render'],
zip_safe=False,
install_requires=[
'Beaker>=1.0.1',
'Beaker>=1.0.4',
],
entry_points="""
[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