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 support for custom timeout #3

Closed
wants to merge 2 commits into from
Closed

Conversation

magarcia
Copy link

Very useful for multiple servers with an independent/not synced cache.

@BertrandBordage
Copy link
Member

Could you describe a precise scenario? I don’t understand why that would be useful.

@magarcia
Copy link
Author

If I have a django application with cachalot connected to a remote DB and in another server a process that modifies the same DB periodically. If django app not writes in the same tables that the remote process, I will not see the changes in DB.
With a timeout in cache, I will see the updates that the process did.

Note that in the pull request, I set timeout None by default, in other words infinite.

@BertrandBordage
Copy link
Member

(Ignore the failed Travis build, I broke a thread-safety test this week)

If those two Django instances are also connected to the same cache server, every modification is impacted on both instances. In this case, no need for a timeout.

If you use different caches, then you must not use cachalot, as it could ruin your database:
Suppose you use separate caches connected to the same DB with a 1 hour timeout. If someone changes an object on the first Django instance, then someone also wants to modify it on the second instance 30 minutes later. The second form can show data as it was before the first modification. If the second user saves, the modifications from the previous save can be 'canceled' by stale data.

I know that other solutions like johnny-cache, django-cache-machine, and django-cacheops allow finite timeouts. But in my opinion, the only reason for this is that they all fail to automatically invalidate their cache. I used all these solutions in production (especially johnny-cache, during 2-3 years), and unfortunately lost a lot of time debugging mysterious bugs in my code when it was actually invalidation issues. For example, johnny-cache broke my django CMS page trees several times. Why? Because the CMS uses django-mptt, django-mptt uses raw queries to update data, and johnny-cache doesn’t invalidate raw queries. And johnny-cache was (before Django 1.6) by far the less flawed ORM caching solution!

Cachalot is not meant to work approximately, I want it to work perfectly out of the box, without getting in the way. That’s why I wrote “no worry” in the slogan.

So, no timeout.

However, there may be an alternative solution to this issue: multiple cache locations, as it is implemented for redis and for memcached. If you specify the local cache as master and remote caches as slaves, the caches should be correctly synchronized and you can still have a fast local cache access. I’ll have to add this to the tests.

What do you think of all this?

@BertrandBordage
Copy link
Member

Closing this issue and marking it as invalid, as I don’t see why that would be relevant.
If you have more reasons in favor of a timeout, feel free to keep commenting on this issue!

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

Successfully merging this pull request may close these issues.

None yet

2 participants