为Django缓存的模板加载器重置缓存 [英] Resetting cache for Django cached template loader

查看:315
本文介绍了为Django缓存的模板加载器重置缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django 1.2引入了一个新的模板加载器,它将数据存储在缓存中( django.template.loaders.cached.Loader )。



不幸的是,我没有找到有关缓存无效的信息,以及重新设置的时间和方式。



我想在我的服务器,但我不确定,它将重置在django重新启动(这将足够我)。

解决方案

通过挖掘django的来源,您可以找到当前服务器实例的模板加载器存储在 django.template.loader.template_source_loaders



当您使用缓存加载程序时,那里只有一个装载器。所以你可以得到它,并调用其重置功能来重置模板缓存。



这里是一些代码片段,我没有自己测试。



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

$ / code>

如果您检查 django.template.loaders.cached ,您可以看到django只需使用一个变量 template_cache 将模板名称保存到模板路径缓存中。它不使用memcached。所以当django重新启动时应该重置。


Django 1.2 introduced a new template loader, that stores data in cache ( django.template.loaders.cached.Loader ).

Unfortunatly, i failed to find any info on how the cache is invalidated and when and how it is reset.

I want to use this on my server, but i'm not sure, that it would reset on django restart (that would be enough for me).

解决方案

By digging into django's source, you could find the template loaders for current server instance are stored at django.template.loader.template_source_loaders.

When you're using cached loader, there would be only one loader out there. So you can get it and calls its reset function to reset template cache.

Here are some code snippets, I haven't test it myself.

from django.template.loader import template_source_loaders
loader = template_source_loaders[0]
loader.reset()

If you check django.template.loaders.cached, you can see that django simply use one variable template_cache to hold the template name to template path cache. It doesn't use memcached. So it should be reset when django restart.

这篇关于为Django缓存的模板加载器重置缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆