简体   繁体   中英

Not caching view in Django LocMemCache

I am trying to cache a class based view like so

urls.py

from django.views.decorators.cache import cache_page
from django.conf.urls import url
urlpatterns = [
    url(r'^/awesome-url$', cache_page(60 * 60)(TemplateView.as_view(template_name="awesome.html")), name="awesome"),
]

settings.py

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'unique-snowflake'
    }
}

My hope was to have my views cached and I wanted to verify that this was happening by inspecting it with:

from django.core.cache.backends import locmem
print locmem._caches
>{}

Source: Contents of locmem cache in django?

Sadly the backend is empty. So I am doubtful that the view is being cached, can anyone help?

As I said in that linked answer, the LocMem cache really is what the name describes: a local memory cache. It's just a global variable inside each process, which is only accessible inside that process.

There's no way for a command in the shell to access the contents of the local memory cache running in the server.

Use a different cache backend, or print the cache values from inside your views.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM