Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a descriptor to clear foreign cache #2

Open
vaab opened this issue Feb 4, 2015 · 0 comments
Open

Add a descriptor to clear foreign cache #2

vaab opened this issue Feb 4, 2015 · 0 comments

Comments

@vaab
Copy link
Member

vaab commented Feb 4, 2015

Often, after calculating a method, we know that we invalidated other cached values... A good example would be ORM, an instance of a record in the database needs cached elements and cached complex function dependent on data of the records, but would then gets invalidated when some write function is called.

This is a little bit like a reverse key: it's not anymore the responsibility of the cache to detect invalidation but foreign functions that could clear the cache. Notice that it's maybe a lesser way to tackle invalidated cache in most situation compared to find the correct key lambda, and I'd like to find a better scenario where it's clear that the key function can't handle it in an elegant way.

>>> class A(object):
...    @cache
...    def complex_fun_on_record_data(self):
...        print 'Compute foo()'
...        return 'hello'
...
...    @classmethod
...    @cache
...    def bar(cls):
...        print "Compute bar()"
...        return "bye"
...
...    @clear_cache(foo)
...    @clear_cache(bar)
...    def data_changed(self):
...        pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant