Bahus / easy_cache

Caching and invalidation have never been so easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refresh and invalidate cache question

ju5t opened this issue · comments

commented

I can't seem to figure out how to refresh or invalidate the cache of a property in a model. We're caching API calls as follows:

class ABC(models.Model):
    @ecached_property('manufacturer:{self.id}', 86400)
    def manufacturer(self):
        return 'API'

Reading the documentation I assumed that to invalidate this entry I would do

item = ABC.object.get(id=1)
ABC.manufacturer.invalidate_cache_by_key(item)

This returns an error:

ValueError: Parameter "'self'" is required for "manufacturer:{self.id}"

Would you mind pointing me in the right direction?

Hi, thank you for reporting the issue, it looks like a bug.
Until I fix it, you can use the following approach:

from easy_cache import invalidate_cache_key, create_cache_key

invalidate_cache_key(create_cache_key('manufacturer', item.id))
commented

Thanks for the update and workaround (and pretty awesome package!).

@ju5t Hi! Could you please install new version easy-cache==1.1.0 and let me know if the problem is fixed or not. Thank you!

commented

Unfortunately the error was still there. I've implemented the workaround for now which works perfectly.

Hi!
This error didn't reproduce with 1.1.0 version, the issue is done

@amokryshev Thank you for the validation!

commented

@amokryshev we need the workaround for it to work so I am curious what you're doing differently. Could you explain this?

@ju5t Hi! actually i've done nothing, Oleg proposed me to fix the bug, but it coudn't reproduced, all works fine.

I've publish my environment, take a look at the test_issue_8/tests.py https://github.com/amokryshev/easy-cache-issue-8