简体   繁体   English

未在Django LocMemCache中缓存视图

[英]Not caching view in Django LocMemCache

I am trying to cache a class based view like so 我试图像这样缓存基于类的视图

urls.py 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 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? 来源: Django中locmem缓存的内容?

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. 就像我在链接的答案中所说的那样,LocMem缓存实际上就是名称所描述的: 本地内存缓存。 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. Shell中的命令无法访问服务器中运行的本地内存缓存的内容。

Use a different cache backend, or print the cache values from inside your views. 使用其他缓存后端,或从视图内部打印缓存值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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