wouldn't a template tag work best in a case like this? something like {% NavBar %} or {% GetNav NavName %}
that way you can have your own cache code inside you template tag code, like storing the database result into memcached or redis and avoid a relational db call each page. them you you modify you navigation data model you can you invalidate the cache and recreate it. it will also be a lot simplier to reuse in other projects as you wont have to inlcude a decorator on each view. On Sep 30, 2:59 am, Victor Hooi <victorh...@gmail.com> wrote: > Hi, > > We have a common navigation bar on nearly every page (view) that contains a > dropdown - this dropdown is populated with items from a database table. This > dropdown also has AJAX behaviour attached to it. > > I'm thinking I can create a decorator that will retrieve the list from the > database, and return a Python list > > We can then wrap every single view in this decorator, and then pass the list > to the template for rendering. > > Firstly - is there a more elegant alternative, rather than wrapping every > single view in this decorator? (Middleware? Or is that a poor fit here? > Anything else?). > > And secondly - are there are any performance issues here? We're making > database calls with every single view, just to get a list for a navigation > dropdown. Smarter way? > > I know I can use the caching middleware to cache entire pages, or even > template fragments - but how about caching a single list() like this? What > are other methods people are using to tackle this? > > Cheers, > Victor -- 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.