Skip to content

Commit

Permalink
Refactor decorator and cache key format
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed May 8, 2018
1 parent 8b25545 commit f804678
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Products/ZCatalog/Catalog.py
Expand Up @@ -595,7 +595,7 @@ def _search_index(self, cr, index_id, query, rs):

return rs

@cache()
@cache
def _apply_query_plan(self, cr, query):

plan = cr.plan()
Expand Down
14 changes: 9 additions & 5 deletions src/Products/ZCatalog/cache.py
Expand Up @@ -31,10 +31,11 @@ def __init__(self, catalog, query=None):
self.key = self.make_key(query)

def get_id(self):
parent = aq_parent(self.catalog)
catalog = self.catalog
parent = aq_parent(catalog)
path = getattr(aq_base(parent), 'getPhysicalPath', None)
if path is None:
path = ('', 'NonPersistentCatalog')
path = ('', 'NonPersistentCatalog', id(catalog))
else:
path = tuple(parent.getPhysicalPath())
return path
Expand Down Expand Up @@ -73,7 +74,7 @@ def make_key(self, query):
keys.append((name, counter, value))

key = frozenset(keys)
cache_key = '%s-%s' % (self.cid, hash(key))
cache_key = (self.cid, key)
return cache_key

def _convert_datum(self, index, value):
Expand Down Expand Up @@ -117,5 +118,8 @@ def _apply_query_plan_cachekey(method, catalog, plan, query):
return cc.key


def cache():
return ram.cache(_apply_query_plan_cachekey)
def cache(fun):
@ram.cache(_apply_query_plan_cachekey)
def decorator(*args, **kwargs):
return fun(*args, **kwargs)
return decorator

0 comments on commit f804678

Please sign in to comment.