It sounds like the problem is that you are caching the whole page
using the site wide cache. Maybe things would work better if you used
the low level cache api.[1]

from django.core.cache import cache

MY_STORY_CACHE_KEY = "story_list"
def story_list(request):
  story_list = cache.get(MY_STORY_CACHE_KEY)
  if story_list is None: #Cache miss
    story_list = get_stories()
    cache.set(MY_STORY_CACHE_KEY, story_list, 60 * 5) #Cached for five
minutes
  vote_list = get_votes()
  return render_to_response(template_name,
                dict(vote_list=vote_list, story_list=story_list),
                context_instance=RequestContext(request)

Also, you might just to temple level caching.[2]

Finally, if you aren't having performance issues yet, maybe don't
worry about caching. (Premature optimization and all that...)

Hope that helps,
Alex

[1]http://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-
cache-api
[2]http://docs.djangoproject.com/en/dev/topics/cache/#template-
fragment-caching

On Jul 21, 9:59 am, Norman <n.rosi...@gmail.com> wrote:
> per-view cache is not a solution because I need only a method to
> retrieve fresh (not cached) data from middleware.
>
> I wanna take cached list of stories and not cached vote results for
> it.
>
> regards, Norman
>
> On Jul 21, 3:13 pm, Michael <newmani...@gmail.com> wrote:
>
> > On Tue, Jul 21, 2009 at 9:02 AM, Norman <n.rosi...@gmail.com> wrote:
>
> > > Hi all,
>
> > > I cache my view that show a list of stories, but I have also small
> > > voting button (like digg). Voting is done be middleware class (it
> > > reads user IP), so I can ask for view with list of stories and tell
> > > that this list shall be cached and I have to ask middleware for vote
> > > results.
>
> > > Unfortunaltely when cache is ON my middleware voting class isn't asked
> > > for voting results.
>
> > > What can I do to mix cache from view and live results from my
> > > middleware voting class?
>
> > From the per-site cache 
> > docshttp://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache:
>
> > New in Django 1.0: Please, see the release
> > notes<../../releases/1.0/#releases-1-0>
> > If a view sets its own cache expiry time (i.e. it has a max-age section in
> > its Cache-Control header) then the page will be cached until the expiry
> > time, rather than CACHE_MIDDLEWARE_SECONDS. Using the decorators in
> > django.views.decorators.cache you can easily set a view's expiry time (using
> > the cache_control decorator) or disable caching for a view (using the
> > never_cache decorator). See the using other
> > headers<#controlling-cache-using-other-headers> section
> > for more on these decorators.
>
> > So all you need to do is make the cache on the view different (never_cache
> > decorator might be good here).
>
> > Read more on that page for the per-view cache.
>
> > Hope that helps,
>
> > Michael
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to