django-dbtemplates
django-dbtemplates copied to clipboard
Caching behaviour with default settings
Since the introduction of the CACHES
setting Django by default uses the LocMemCache
backend. Using multiple Django processes on the server, each process maintains it's own cache (as documented here: https://docs.djangoproject.com/en/1.6/topics/cache/#local-memory-caching).
I think this yields to outdated templates in the cache of all processes, except the one, that was used to save a change through the Django Admin.
Setting DBTEMPLATES_CACHE_BACKEND
to None
does not change the behaviour.
I think this behaviour needs to be documented, because I have to actively disable the LocMemCache setting to fix the problem with stale db-templates.
If I don't use caching at all in a project, I would normally not think about altering the Django default setting.
Environment: Django 1.6.2, Python 2.7.5, dbtemplates 1.3
Possibly related to #43
Edit: Using a DummyCache
as the default cache fixed the problem with stale db-templates completely.
Have you tried setting a LOCATION
of the locmem backends as described in the Django settings?
No, because the point I wanted to make is: "If my project does not use Django's Cache Framework at all, I will never think about changing the CACHES setting and that will break dbtemplates".
If I make any use of Django caching in my project, I will definately use a cache backend thats works for my setup and then dbtemplates will of course work correctly.
The documentation says (https://github.com/jezdez/django-dbtemplates/blob/develop/docs/advanced.txt#L7):
To enable one of them you need to specify a setting called DBTEMPLATES_CACHE_BACKEND ...
And:
Starting in version 1.0 dbtemplates allows you also to set the new dict-based CACHES setting,
which was introduced in Django 1.3.
All you have to do is to provide a new entry in the CACHES dict named 'dbtemplates', e.g.:
What's missing is a clear indication that, If I do nothing, it will use CACHES['default'] and I have to make sure, that it's configured to work for my envirnoment.
After reading the documentation I thought that dbtemplates would only use the cache, if I activated it somehow. But it does it silently by default. Then Django's default (LocMenCache) combined with my Process-based Django Workers lead to the strange behaviour of seeing outdated templates from some workers.
I opened the ticket because I think it might save others some time if this would be mentioned in the documentation.
Ah, okay, thanks for the clarification, I'm sorry you had to find out that implicit behavior the hard way. This needs to be clarified indeed.
@arneb thank you for this problem report, would you mind submitting a pull request against the current docs?
Maybe this will be solved via PR #131