hephex / asyncache

Helpers to use cachetools with async functions
MIT License
93 stars 12 forks source link

How to use lock #11

Open oxlade39 opened 1 year ago

oxlade39 commented 1 year ago

How is one supposed to safely evict entries?

I'm going off of the cachetools documentation here and thought that to clear the cache I would need to do something like documentation in this place, eg:

# always use the key function for accessing cache items
with get_pep.cache_lock:
    get_pep.cache.pop(get_pep.cache_key(42), None)

However when using asyncache I don't appear to see any of the usual methods like cache_lock, cache_clear, cache_info etc?

How does one get access to those methods in the async wrapper?

ps. Thanks for the great library.

hephex commented 1 year ago

It's not currently possible, but it's on my todo list. I upgraded the library recently to support the new version, but I postponed this change (I should have made it clear in the changelog 😓 ).

I might be able to get it done in the next few days because it should be pretty straightforward.

ps. Thanks for the great library.

Thank you! 😊

arossert commented 1 year ago

Hi @hephex I'm missing the ability to call cache_clear from within the decorated method, is this planned to be added?

ivandigiusto commented 11 months ago

Hi @hephex, Really appreciate making async cachetools available to the public.

Any chance to get the new cache methods (cache clear, info, lock, ...) available in asyncache?

Thanks!

Drachenfels commented 5 days ago

Just for reference, to have simple access to the cache, lock, etc all that is needed is to add:

https://github.com/hephex/asyncache/blob/master/asyncache/__init__.py#L110

        def cache_clear():
            cache.clear()

        wrapper.cache = cache
        wrapper.cache_key = key
        wrapper.cache_lock = lock
        wrapper.cache_clear = cache_clear

        return functools.wraps(func)(wrapper)

Of course, it's a bit simplistic but it does the work.