django memcached optimalization -


i deploying social networking site django on vps, current stack nginx, postgresql, gunicorn. going add memcached, forced use {% cache %} tag in templates or low level api in views though, each site dynamic authenticated users. have 1 question regarding {% cache %} tag, lets input variable within cache tag so:

{% cache 500 x %} {{ variable }} {% endcache %} 

lets assume {{ variable }} in fact consuming database query written in related view. best way prevent database hit view (lets assume query evaluated in view) , should cache low level api? if isnt bit redundant cache in both places? please give me thoughs convenient method. btw, know example trivial, if wanted cache variable in view, surely need use cache tag cache loops, multiple html lines generated python etc. thanks

first, usage of authentication in site doesn't involve usage of low level cache in both sides views , templates, note instance can {% cache 500 user %} , save different chunk of code of each user of site.

answering second question: in general, can prevent database hits caching templates. evaluate query there instead of doing view, , make dynamic clean of keys when content changes instead of using fixed expiration times, way let better performance result. also, take in mind cache tag saves chunk of html code.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -