Querysets are evaluated lazily.[1][2] You may have better success using template fragment caching[3] to cache the menu output.
[1] https://docs.djangoproject.com/en/dev/topics/db/queries/#querysets-are-lazy [3] https://docs.djangoproject.com/en/dev/ref/models/querysets/#when-querysets-are-evaluated [3] https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs#template-fragment-caching On Jul 15, 2:26 pm, Rob <robvan...@zonnet.nl> wrote: > I have setup caching with memcached for my site. This works well > except from this part of my view. My idea was to store all menu items > in the cache, and apply a filter later on to decide if they belong to > the left or top menu. > > menu = cache.get(menu_cache_key) > if menu: > menu_left = menu.filter(menu_left = True) > menu_top = menu.filter(menu_top = True) > > I thought that apply the .filter() on the menu would not cause a query > on the database, but it does. So the menu is retrieved from the cache, > and after that the menu items are retrieved from the database (which > makes the caching useless). I found out about this because changes in > the menu are applied immediately on the webpage. > > Is this normal behaviour, and should I make multiple entries into the > cache for the left- and topmenu, or is there a way to get this > working? > > Rob -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.