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
DjangoCache Out of Disk Space Scenario #62
Comments
After you "rm -r /var/tmp/django_disk_cache" just restart your web server. The directory and supporting SQLite database will be created for you. |
Here's the relevant docs: https://docs.djangoproject.com/en/1.11/topics/cache/#basic-usage http://www.grantjenks.com/docs/diskcache/api.html#djangocache To use the API, open a Django shell with "python manage.py shell" then import the cache as you do in your views and call "cache.clear()" |
Is there a diskcache bug that caused the out-of-space scenario? |
Wow that was quick! No it wasn't a diskcache bug that caused the out-of-space scenario just my stupid fault for setting the cache too large. I've restarted the and deleted /var/tmp/django_disk_cache multiple times and seen it's been recreated but the error remains, the only way I've been able to fix it is by changing the django cache type. I'll try cache.clear() thanks, also where is the sqlite db located as I'd like to try deleting that as well |
The SQLite database is in that directory. I think it's "/var/tmp/django_disk_cache/cache.db" |
Actually it's a little more complicated. There's 8 or so subdirectories and it's in one of those. |
Do you have a situation where you assume the cache is warmed? Meaning, are there keys you assume will always be there? It's hard to tell without more stack trace in your exception. |
Still no joy, have deleted /var/tmp/django_disk_cache/, run 'from django.core.cache import cache -> clear.cache()' in a shell, restarted nginx and gunicorn. I'm sure not what you mean by assuming the keys are always there, I'm using it in conjunction with fancy-cache https://github.com/peterbe/django-fancy-cache, if there's a miss on the keys then I believe it executes the code as normal then caches it. Been working well for a week or two until I deleted that directory. Here's the stack trace:
|
That behavior looks expected if the key is not in the cache. See the Django source for reference: https://github.com/django/django/blob/1.11.8/django/core/cache/backends/base.py#L177 So the question then is why does fancy-cache assume the key is in the cache? |
Well I assumed the keys were in this sqlite db I can't find which still has the old keys from before I deleted /var/tmp/django_disk_cache, but this isn't the case? /var/tmp/django_disk_cache has been recreated but there's no sqlite db there, so I definitely must be using the original |
Assuming your caches setting looks something like: CACHES = {
'default': {
'BACKEND': 'diskcache.DjangoCache',
'LOCATION': '/var/tmp/django_disk_cache/',
'OPTIONS': {
'size_limit': int(10e9),
},
},
} You can also test the caching layer with:
Does that work? |
Yes that works, except instead of '0' nothing is returned, which I assume is the same |
Not the same actually. The default return value is None which is not displayed by the Python interpreter. Sounds like your cache is not getting created. Usually that's a file system permissions issue. |
Ah you're right, it had: drwxr-xr-x silentjay www-data changed it to: drwxr-xr-x silentjay silentjay and it's now working! either that or it's because I got mad and ran the clear cache command about 20 times in a row. I also changed size_limit back from 2 ** 16 to 2 ** 32 |
Glad it's working now! I wonder why it didn't error earlier? I tried to support this scenario with an informative exception:
Also, if I setup a dummy Django project, I get that error again:
|
Oh wait! I just noticed your comment about the size limit. "2 ** 16" is 65,536 which is really much too low to be practical. Your cache was likely evicting keys to meet the size limit just after they were written. It's happened to me before too. |
That would be it then. Might be worth a warning in the docs. Thanks again for the help. |
I had to do an emergency delete of the disk cache /var/tmp/django_disk_cache as my server had run out of disk space.
Ever since I receive Django errors
Disabling DjangoCache is the ony current fix. I've checked the Django db and there's no corresponding table for DjangoCache. There's obviously some reference to these keys somewhere but I can't find them. The docs make mention to a sqlite db, but I've searched my installation and can't find it.
The help for DjangoCache also mention a
clear
command, which I assume I'm meant to run in a python shell, but I can't figure out how to run it and there's no examples.The text was updated successfully, but these errors were encountered: