Commit fe096a89 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

rename decorator function name and id generator argument name.

* caching_class_method_decorator -> caching_instance_method
* cache_id_func -> cache_id_generator


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29775 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ae1bdb15
...@@ -158,7 +158,7 @@ class CachingMethod: ...@@ -158,7 +158,7 @@ class CachingMethod:
def __init__(self, callable_object, id, cache_duration=180, def __init__(self, callable_object, id, cache_duration=180,
cache_factory=DEFAULT_CACHE_FACTORY, cache_factory=DEFAULT_CACHE_FACTORY,
cache_id_func=None): cache_id_generator=None):
"""Wrap a callable object in a caching method. """Wrap a callable object in a caching method.
callable_object must be callable. callable_object must be callable.
...@@ -176,7 +176,7 @@ class CachingMethod: ...@@ -176,7 +176,7 @@ class CachingMethod:
self.callable_object = callable_object self.callable_object = callable_object
self.cache_duration = cache_duration self.cache_duration = cache_duration
self.cache_factory = cache_factory self.cache_factory = cache_factory
self.cache_id_func = cache_id_func self.cache_id_generator = cache_id_generator
def __call__(self, *args, **kwd): def __call__(self, *args, **kwd):
"""Call the method or return cached value using appropriate cache plugin """ """Call the method or return cached value using appropriate cache plugin """
...@@ -223,9 +223,9 @@ class CachingMethod: ...@@ -223,9 +223,9 @@ class CachingMethod:
## generate cache id out of arguments passed. ## generate cache id out of arguments passed.
## depending on arguments we may have different ## depending on arguments we may have different
## cache_id for same method_id ## cache_id for same method_id
cache_id_func = self.cache_id_func cache_id_generator = self.cache_id_generator
if cache_id_func is not None: if cache_id_generator is not None:
return cache_id_func(method_id, *args, **kwd) return cache_id_generator(method_id, *args, **kwd)
return str((method_id, args, kwd)) return str((method_id, args, kwd))
allow_class(CachingMethod) allow_class(CachingMethod)
...@@ -278,8 +278,8 @@ def generateCacheIdWithoutFirstArg(method_id, *args, **kwd): ...@@ -278,8 +278,8 @@ def generateCacheIdWithoutFirstArg(method_id, *args, **kwd):
# is 'self' that can be ignored to create a cache id. # is 'self' that can be ignored to create a cache id.
return str((method_id, args[1:], kwd)) return str((method_id, args[1:], kwd))
def caching_class_method_decorator(*args, **kw): def caching_instance_method(*args, **kw):
kw.setdefault('cache_id_func', generateCacheIdWithoutFirstArg) kw.setdefault('cache_id_generator', generateCacheIdWithoutFirstArg)
def wrapped(method): def wrapped(method):
# The speed of returned function must be fast # The speed of returned function must be fast
# so we instanciate CachingMethod now. # so we instanciate CachingMethod now.
......
...@@ -526,7 +526,7 @@ class ERP5TypeInformation(XMLObject, ...@@ -526,7 +526,7 @@ class ERP5TypeInformation(XMLObject,
_getRawActionInformationList, _getRawActionInformationList,
id='_getRawActionInformationList', id='_getRawActionInformationList',
cache_factory='erp5_content_long', cache_factory='erp5_content_long',
cache_id_func=lambda method_id, *args, **kwd:str(method_id)) cache_id_generator=lambda method_id, *args, **kwd:str(method_id))
security.declarePrivate('getRawActionInformationList') security.declarePrivate('getRawActionInformationList')
def getRawActionInformationList(self): def getRawActionInformationList(self):
......
...@@ -71,7 +71,7 @@ except ImportError: ...@@ -71,7 +71,7 @@ except ImportError:
try: try:
from Products.ERP5Type.Cache import enableReadOnlyTransactionCache, \ from Products.ERP5Type.Cache import enableReadOnlyTransactionCache, \
disableReadOnlyTransactionCache, CachingMethod, \ disableReadOnlyTransactionCache, CachingMethod, \
caching_class_method_decorator caching_instance_method
except ImportError: except ImportError:
LOG('SQLCatalog', WARNING, 'Count not import CachingMethod, expect slowness.') LOG('SQLCatalog', WARNING, 'Count not import CachingMethod, expect slowness.')
def doNothing(context): def doNothing(context):
...@@ -84,7 +84,7 @@ except ImportError: ...@@ -84,7 +84,7 @@ except ImportError:
self.function = callable self.function = callable
def __call__(self, *opts, **kw): def __call__(self, *opts, **kw):
return self.function(*opts, **kw) return self.function(*opts, **kw)
def caching_class_method_decorator(*args, **kw): def caching_instance_method(*args, **kw):
return lambda method: method return lambda method: method
enableReadOnlyTransactionCache = doNothing enableReadOnlyTransactionCache = doNothing
disableReadOnlyTransactionCache = doNothing disableReadOnlyTransactionCache = doNothing
...@@ -936,7 +936,7 @@ class Catalog(Folder, ...@@ -936,7 +936,7 @@ class Catalog(Folder,
@profiler_decorator @profiler_decorator
@transactional_cache_decorator('SQLCatalog.getColumnMap') @transactional_cache_decorator('SQLCatalog.getColumnMap')
@profiler_decorator @profiler_decorator
@caching_class_method_decorator(id='SQLCatalog.getColumnMap', cache_factory='erp5_content_long') @caching_instance_method(id='SQLCatalog.getColumnMap', cache_factory='erp5_content_long')
@profiler_decorator @profiler_decorator
def getColumnMap(self): def getColumnMap(self):
""" """
...@@ -2191,7 +2191,7 @@ class Catalog(Folder, ...@@ -2191,7 +2191,7 @@ class Catalog(Folder,
@profiler_decorator @profiler_decorator
@transactional_cache_decorator('SQLCatalog._getSearchKeyDict') @transactional_cache_decorator('SQLCatalog._getSearchKeyDict')
@profiler_decorator @profiler_decorator
@caching_class_method_decorator(id='SQLCatalog._getSearchKeyDict', cache_factory='erp5_content_long') @caching_instance_method(id='SQLCatalog._getSearchKeyDict', cache_factory='erp5_content_long')
@profiler_decorator @profiler_decorator
def _getSearchKeyDict(self): def _getSearchKeyDict(self):
result = {} result = {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment