3

I'm trying to get entire-site filesystem based caching working for the first time.

I've created /var/tmp/django_cache with 777 permissions.

I've added this to settings.py:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/var/tmp/django_cache',
        'TIMEOUT': 60,
        'OPTIONS': {
            'MAX_ENTRIES': 1000
        }
    }
}

CACHE_MIDDLEWARE_ALIAS = 'default'
CACHE_MIDDLEWARE_SECONDS  = 60
CACHE_MIDDLEWARE_KEY_PREFIX = 'myapp'

And I've updated the relevant part of the middleware classes:

MIDDLEWARE_CLASSES = (
    ....
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    ...
)

Is there anything else I need to do? I'm not seeing any files get created in /var/tmp/django_cache when I browse around. I touched wsgi.py, restarted apache. No dice.

user3449833
  • 779
  • 2
  • 10
  • 28
  • everything looks good. just make sure the location can be accessed as in user:group permissions are also set on the django_cache folder. if the folder can not be accessed (you can give permissions like say for ex: chown user:group /var/tmp/django_cache); I think django will ignore it (I guess?). I tested the same settings on windows, and it works fine.. ofcourse on windows the location should be more like c:\\users\\<>\\django_cache\\ and once I set it up correctly, you should see the cache files like below 1d76aaae6e0fb39df3c2eb8ca30a5913.djcache in the above folder. – rreddy Feb 09 '16 at 14:52
  • `from django.core.cache import cache;cache.set("foo","baz");cache.get("foo")`. Works? – Aviah Laor Feb 10 '16 at 18:21
  • So **what do you mean by "No dice."?** Are you aware your code needs to put things into the cache by `cache.set`? And read them again explicitly by `cache.get`? If you do that, what exactly does not appear to work? – Lutz Prechelt Aug 05 '16 at 08:25
  • In Django 1.11, if you're using template caching, make sure LOCATION is using an absolute path. If you use a relative path it won't give you an error but it also won't work for you. – Kalob Taulien Mar 17 '18 at 21:59

0 Answers0