youknowone / ring

Python cache interface with clean API and built-in memcache & redis + asyncio support.
http://ring-cache.readthedocs.io/en/latest/
Other
480 stars 37 forks source link

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

Closed leeransetton closed 5 years ago

leeransetton commented 5 years ago

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?

youknowone commented 5 years ago

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

leeransetton commented 5 years ago

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'
youknowone commented 5 years ago

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.

leeransetton commented 5 years ago

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 :)