def test_decorator(self):
        cache = self.cache(2)
        wrapper = cachetools.cached(cache)(self.func)

        self.assertEqual(len(cache), 0)
        self.assertEqual(wrapper.__wrapped__, self.func)

        self.assertEqual(wrapper(0), 0)
        self.assertEqual(len(cache), 1)
        self.assertIn(cachetools.hashkey(0), cache)
        self.assertNotIn(cachetools.hashkey(1), cache)
        self.assertNotIn(cachetools.hashkey(1.0), cache)

        self.assertEqual(wrapper(1), 1)
        self.assertEqual(len(cache), 2)
        self.assertIn(cachetools.hashkey(0), cache)
        self.assertIn(cachetools.hashkey(1), cache)
        self.assertIn(cachetools.hashkey(1.0), cache)

        self.assertEqual(wrapper(1), 1)
        self.assertEqual(len(cache), 2)

        self.assertEqual(wrapper(1.0), 1)
        self.assertEqual(len(cache), 2)

        self.assertEqual(wrapper(1.0), 1)
        self.assertEqual(len(cache), 2)
 def typedkey(*args, **kwargs):
     key = cachetools.hashkey(*args, **kwargs)
     key += tuple(type(v) for v in args)
     key += tuple(type(v) for _, v in sorted(kwargs.items()))
     return key
Example #3
0
def update_workflow_cache(wf_def_id, spec):
    with _WF_CACHE_LOCK:
        # We have to use hashkey function because @cached uses it implicitly.
        _WF_CACHE[hashkey(wf_def_id)] = spec
Example #4
0
def strhash(*args, **kwargs):
    return str(hashkey(*args, **kwargs))
Example #5
0
 def value(*args, **kwds):
     """
     returns the generated hashkey of the *args and **kwds
     """
     return hashkey(*args, **kwds)