youknowone/ring

Can't call clear() if I don't use asyncio

leeransetton opened this issue · 4 comments

I'm using @ring.lru and I don't have asyncio, but I need the clear() function.
Is there a way to add it somehow?

There was a bug in clear. it is fixed in #142. is this related issue with yours?

That's not it, please see my code sample below:

import ring
@ring.lru(maxsize=10)
def foo(a):
    print(a)
    return a
foo(1)
1
1
foo.clear()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/leeran/workspace/user_state_builder/.pyenv/local/lib/python2.7/site-packages/wirerope/rope.py", line 79, in __getattr__
    return getattr(self._wire, name)
  File "/home/leeran/workspace/user_state_builder/.pyenv/local/lib/python2.7/site-packages/ring/func/base.py", line 681, in __getattr__
    attr = getattr(self._rope.user_interface, name)
AttributeError: 'CacheUserInterface' object has no attribute 'clear'

For now, foo.storage.backend.clear() will work.

Let's see foo.clear() make sense or not. It doesn't make sense for most of other backends, but looks fine for lru at a glance.

https://docs.python.org/3/library/functools.html#functools.lru_cache has a function cache_clear(), I thought it only makes sense that ring.lru will have something similar.

foo.storage.backend.clear() works perfect.

Thanks :)