Skip to content

Commit

Permalink
allow custom cache objects (#4)
Browse files Browse the repository at this point in the history
allow custom cache objects

* update changelog

* cosmetics
  • Loading branch information
janwijbrand committed Apr 26, 2017
1 parent 99e5c24 commit 660ee3d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 3 additions & 4 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ CHANGES
2.2 (unreleased)
----------------

- Nothing changed yet.

- The caching option to searchResults now accepts a dict-like value and it
will use that to allow for caching results over multiple searchResults()
calls. The cache invalidation then is the responsibility of the caller.

2.1 (2017-02-07)
----------------
Expand All @@ -19,7 +20,6 @@ CHANGES

- Fix log line in Text term for invalid text search.


2.0 (2016-09-07)
----------------

Expand Down Expand Up @@ -48,7 +48,6 @@ CHANGES

* Add support for an All query.


1.1.1 (2012-06-22)
------------------

Expand Down
11 changes: 10 additions & 1 deletion src/hurry/query/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ def searchResults(
result in set to the given start position.
Optionally provide a `caching` parameter to cache terms result
across multiple search queries.
across multiple search queries. Accepted parameter values are:
`True` for `threading.local` based and transaction boundary-aware
caching. The cache for multiple `searchResults()` calls is
invalidated at the end of the transaction.
`False` to cache only for individual `searchResults()` calls.
Or a `dict`-like object where invalidation is handled by the
caller of the multiple `searchResults()` call.
"""


Expand Down
9 changes: 6 additions & 3 deletions src/hurry/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def __iter__(self):
yield self.get(uid)



class Timing(object):

def __init__(self, key=None, order=0):
Expand Down Expand Up @@ -215,10 +214,14 @@ def searchResults(
context = getSiteManager()
else:
context = IComponentLookup(context)
if caching:

if caching is True:
cache = transaction_cache.use(context)
else:
elif caching is False:
cache = {}
else:
# A custom cache object was injected, use it.
cache = caching

timer = None
if timing is not False:
Expand Down

0 comments on commit 660ee3d

Please sign in to comment.