From 83bdff72d405b5253d79c31b2ada3021f08c751f Mon Sep 17 00:00:00 2001 From: Mahmoud Hashemi Date: Fri, 10 Apr 2015 09:22:15 -0700 Subject: [PATCH] quick fix to cached, adding a sanity test, fixes #12 --- boltons/cacheutils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/boltons/cacheutils.py b/boltons/cacheutils.py index a5f7631..ffb21a2 100644 --- a/boltons/cacheutils.py +++ b/boltons/cacheutils.py @@ -416,10 +416,21 @@ def cached(cache, typed=False): check. Default ``False``, setting to ``True`` causes the cache keys for ``3`` and ``3.0`` to be considered unequal. + >>> my_cache = LRU() + >>> @cached(my_cache) + ... def cached_lower(x): + ... return x.lower() + ... + >>> cached_lower("CaChInG's FuN AgAiN!") + "caching's fun again!" + >>> len(my_cache) + 1 + .. _hashable: https://docs.python.org/2/glossary.html#term-hashable """ def cached_func_decorator(func): return CachedFunction(func, cache, typed=typed) + return cached_func_decorator @@ -445,4 +456,3 @@ if __name__ == '__main__': _test_lri() _test_lru() -