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

cache_on_save is not working as expected #45

Closed
bourivouh opened this issue Aug 26, 2013 · 7 comments
Closed

cache_on_save is not working as expected #45

bourivouh opened this issue Aug 26, 2013 · 7 comments

Comments

@bourivouh
Copy link
Contributor

Hello!
I try to use cache_on_save feature.
In settings.py:

CACHEOPS = {
    'app.model': ('all', DEFAULT_CACHE_TIME, {"cache_on_save": "video"})
}

Model object cached after saving by key conj:app.model:video_id=1 - all right.
But in the next calling of get function (Model.objects.get(video=1)), Model is retrieved from database, not from cache.

It happens because _cache_key return diffrent keys.
That's because when Model is cached after saving we have in _cache_key function:

extra = "cacheops.query.<lambda>"
self.query.default_ordering == True
self.query.used_aliases == set(["app_model"])

But when Model retrieve:

extra = ""
self.query.default_ordering == False
self.query.used_aliases == set([])
@Suor
Copy link
Owner

Suor commented Aug 26, 2013

Hello, thanks for your report. It would be very helpful if you provided a test for it.

You can read here an example how to do that: #29 (comment)

Suor added a commit that referenced this issue Aug 26, 2013
- don't use @cached_as(), which means no lambda signature to extra
  and no unnecessary redis GET request
- use .order_by() to mimic QuerySet.get() behaviour

Should help with #45
@Suor
Copy link
Owner

Suor commented Aug 26, 2013

You can try if that helps. If not try using 'video_id' instead of 'video' in your settings.

@bourivouh
Copy link
Contributor Author

Ok, I'll try to write test.
Using video_id doesn't help.

Suor added a commit that referenced this issue Aug 26, 2013
@Suor
Copy link
Owner

Suor commented Aug 26, 2013

Thanks for test. The thing is it passes.

@bourivouh
Copy link
Contributor Author

Yes, after your last commit.
Could you create new version of cacheops with this fix?

@Suor
Copy link
Owner

Suor commented Aug 26, 2013

I usually let new code to cool down a couple of days before releasing it. Can you use git version (pip can handle this) or just tolerate cache_on_save not working for a while?

@Suor Suor closed this as completed Aug 26, 2013
@bourivouh
Copy link
Contributor Author

Ok, I can wait.
Many thanks for the prompt fix.

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

2 participants