Resetting cache for Django cached template loader

后端 未结 4 1280
花落未央
花落未央 2021-01-02 09:23

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

Unfortunatly, i failed to find any inf

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 10:12

    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.

提交回复
热议问题