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

Caching regression with cachier v3.1.2 #254

Open
dphi opened this issue Nov 25, 2024 · 3 comments
Open

Caching regression with cachier v3.1.2 #254

dphi opened this issue Nov 25, 2024 · 3 comments
Labels

Comments

@dphi
Copy link
Contributor

dphi commented Nov 25, 2024

Hi all, the following code works with cachier 3.0.1.

import datetime
import cachier

cachier.set_default_params(caching_enabled=False, separate_files=True)

class Test:
    def __init__(self, cache_ttl = None):
        self.counter = 0
        if cache_ttl is not None:
            stale_after = datetime.timedelta(seconds=cache_ttl)
            cachier.set_default_params(stale_after=stale_after)
            cachier.enable_caching()

    @cachier.cachier()
    def test(self, param):
        self.counter += 1
        assert self.counter < 2
        return param

if __name__ == "__main__":
    t = Test(cache_ttl=1)
    t.test("a")
    t.test("a")

With version 3.1.2, the caching of the test() function does not work as expected and the assert fails. This probably is not a minimal example yet.

Thanks for looking into it.

Philipp

@dphi dphi changed the title Caching regression for cachier 3.1.2 Caching regression with cachier v3.1.2 Nov 25, 2024
@Borda
Copy link
Contributor

Borda commented Jan 12, 2025

Just a quick question, why do you expect that the second call will not be incremented since you disabled cashing with cachier.set_default_params(caching_enabled=False)?

@Borda Borda added the question label Jan 12, 2025
@dphi
Copy link
Contributor Author

dphi commented Jan 18, 2025

My understanding of the enable_caching() method call in the __init__() is that it activates caching during runtime, even though it was previously deactivated.

@Borda
Copy link
Contributor

Borda commented Jan 19, 2025

I see your confusion, then we shall update the docs with better explanation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants