[Fixed]-Django reloads variables every time a page is clicked

1๐Ÿ‘

โœ…

I would use the low level cache api to do this https://docs.djangoproject.com/en/1.8/topics/cache/. Once the cache is setup it should be as easy as doing the following:

   from django.core.cache import cache

   def view():
        search_tags = cache.get('search_tags')
        if not search_tags: # cache expired
            search_tags = get_searchtags() # substitute for your code
            cache.set('search_tags', search_tags, 60 * 60 * 24 * 7) # cache search tags for 7 days
       return view

This will mean that once every 7 days the search tags list is built and subsequent accesses are extremely quick.

๐Ÿ‘คJeff_Hd

Leave a comment