diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-18 13:56:41 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-18 13:56:41 -0500 |
commit | 4d4e1404d08f0946c1986bfc34523099766418ad (patch) | |
tree | b757d3127a9a85037f2948a1166a7382257b57c8 | |
parent | c4c9187c7c1b9b47e9c8c59c7107a672526b5542 (diff) | |
download | mako-4d4e1404d08f0946c1986bfc34523099766418ad.tar.gz |
get_and_replace is wrong, for now changed to get_or_create like dogpile.cache
-rw-r--r-- | mako/cache.py | 6 | ||||
-rw-r--r-- | mako/codegen.py | 4 | ||||
-rw-r--r-- | mako/ext/beaker_cache.py | 2 | ||||
-rw-r--r-- | test/test_cache.py | 4 |
4 files changed, 8 insertions, 8 deletions
diff --git a/mako/cache.py b/mako/cache.py index b64e94f..2985e69 100644 --- a/mako/cache.py +++ b/mako/cache.py @@ -70,14 +70,14 @@ class Cache(object): def _load_impl(self, name): return _cache_plugins.load(name)(self) - def get_and_replace(self, key, creation_function, **kw): + def get_or_create(self, key, creation_function, **kw): """Retrieve a value from the cache, using the given creation function to generate a new value.""" if not self.template.cache_enabled: return creation_function() - return self.impl.get_and_replace(key, + return self.impl.get_or_create(key, creation_function, **self._get_cache_kw(kw)) @@ -160,7 +160,7 @@ class CacheImpl(object): def __init__(self, cache): self.cache = cache - def get_and_replace(self, key, creation_function, **kw): + def get_or_create(self, key, creation_function, **kw): """Retrieve a value from the cache, using the given creation function to generate a new value. diff --git a/mako/codegen.py b/mako/codegen.py index 5e3dee6..2e15124 100644 --- a/mako/codegen.py +++ b/mako/codegen.py @@ -633,7 +633,7 @@ class _GenerateRenderMethod(object): ) if buffered: s = "context.get('local')."\ - "cache.get_and_replace(%s, lambda:__M_%s(%s), %s__M_defname=%r)" % \ + "cache.get_or_create(%s, lambda:__M_%s(%s), %s__M_defname=%r)" % \ (cachekey, name, ','.join(pass_args), ''.join(["%s=%s, " % (k,v) for k, v in cache_args.items()]), name @@ -644,7 +644,7 @@ class _GenerateRenderMethod(object): else: self.printer.writelines( "__M_writer(context.get('local')." - "cache.get_and_replace(%s, lambda:__M_%s(%s), %s__M_defname=%r))" % + "cache.get_or_create(%s, lambda:__M_%s(%s), %s__M_defname=%r))" % (cachekey, name, ','.join(pass_args), ''.join(["%s=%s, " % (k,v) for k, v in cache_args.items()]), name, diff --git a/mako/ext/beaker_cache.py b/mako/ext/beaker_cache.py index 1d0c26c..90cd09a 100644 --- a/mako/ext/beaker_cache.py +++ b/mako/ext/beaker_cache.py @@ -40,7 +40,7 @@ class BeakerCacheImpl(CacheImpl): return _beaker_cache.get_cache(self.cache.id, **kw), \ {'expiretime':expiretime, 'starttime':self.cache.starttime} - def get_and_replace(self, key, creation_function, **kw): + def get_or_create(self, key, creation_function, **kw): cache, kw = self._get_cache(**kw) return cache.get(key, createfunc=creation_function, **kw) diff --git a/test/test_cache.py b/test/test_cache.py index 1c7b42a..8240e7b 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -19,10 +19,10 @@ class MockCacheImpl(CacheImpl): self.cache = cache self.realcacheimpl = cache._load_impl("beaker") - def get_and_replace(self, key, creation_function, **kw): + def get_or_create(self, key, creation_function, **kw): self.key = key self.kwargs = kw.copy() - return self.realcacheimpl.get_and_replace(key, creation_function, **kw) + return self.realcacheimpl.get_or_create(key, creation_function, **kw) def put(self, key, value, **kw): self.key = key |