Template fragment caching does not seem to work for some custom template tags

I did caching in my django application and used caching of each view through the cache API and fragment caching. On some of my pages I use my own django template tag, this tag is provided by a third-party developer, it takes some arguments in its template tags, and then makes a request to the remote server, receives a response back via XML and then displays the result on my page. Fine. I thought I could easily cache this using fragment caching, so I:

{% load cache %}
{% cache 500 request.user.username %}
{% load third party custom tags %}
{% expensive custom tag set that gets stuff from a third party server via xml %}
{{ some.stuff}}
{% endcache %}

The problem is what I am doing, requests are still being fired to this remote server, it seems that Django does not like to cache these custom template tags. I know memcached works fine, for other views and templates everything works fine. Am I doing something that is incompatible with fragment caching? Is there any way around this?

+3
source share
4 answers

, , , memcached . , , , Django, . HTTP-, , ( ) - .

, , , - , .

+3

? request.user.username :

  • , request.user.username ,

  • , 3

, :

{% cache 500 customxml %}

, :

{% load cache third_party_custom_tags %}
{% cache 500 request.user.username %}
{% expensive custom tag set that gets stuff from a third party server via xml %}
{{ some.stuff}}
{% endcache %}

, - . , , , , Django low- .

0

, , .

, request.user.username , , (, ), .

, , , . , , - - , , ( XML , Django, , ). Django, XML- (), , -, .

0

, - .

Django, , , . . , ( , ) , . , , ( - ), , .

django/templatetags/cache.py. 63 .

0

Source: https://habr.com/ru/post/1721123/


All Articles