title: when to delete the cache entry in django
body: <p>In my django application ,I have a <code>BlogEntry</code> which belongs to a <code>Category</code>.A <code>BlogEntry</code> may belong to many <code>Category</code>s</p>
  
  <pre><code>class BlogEntry(models.Model):
      creationdate=models.DateField(default=date.today)    
      description=models.TextField()
      author=models.ForeignKey(User,null=True)
      categories=models.ManyToManyField(Category)
  
  class Category(models.Model):
      name=models.CharField(unique=True,max_length=50)
      description=models.TextField(blank=True)
  </code></pre>
  
  <p>A user may edit a <code>BlogEntry</code> and in doing so, may remove a <code>Category</code> it was in.</p>
  
  <p>Suppose <code>blogEntry1</code> belonged to <code>java,scala</code> before .If user edits it such that he removes <code>scala</code>.Now the entry has only one category ie <code>java</code></p>
  
  <p>In my list_view I am using cache as below</p>
  
  <pre><code>from django.core.cache import cache
  def list_entries_on_day(request,year,month,day):
      ...
      key = 'entries_day'+'-'+year+'-'+month+'-'+day
      if key not in cache:
          entries = BlogEntry.objects.filter(...args..)
          cache.set(key,entries)
      entries_on_day =cache.get(key)
      ...
  </code></pre>
  
  <p>Suppose I have created 2 entries for today and these are put in cache.If I edit one of these <code>BlogEnty</code>s and remove a category 
  ie;</p>
  
  <pre><code>blogEntry1  has categories :java,scala
  blogEntry2 has categories :dotnet,vbasic
  </code></pre>
  
  <p>Initially I make a query for entries for today and put the result in cache</p>
  
  <p>cache now has <code>[blogEntry1,blogEntry2]</code> against key <code>'entries_day-2012-11-11'</code></p>
  
  <p>Now I edit <code>blogEntry1</code> such that it now has <code>java</code> as category</p>
  
  <p>,do I need to remove the stored entries from cache?(Since the cache contains a <code>BlogEntry</code> object before it's modification)</p>