2

What I am trying to achieve is set a cache_page on a certain class-based view and when a user saves a certain model,, the cache in the page is supposed to be deleted. I tried using:

cache_page(60*1, key_prefix='artists')

then declaring this on the models.py

def save(self, *args, **kwargs):
    from django.core.cache import cache
    cache.delete('artists')
    super(Artist, self).save(*args, **kwargs)

However it did not work.

I tried using:

cache.clear()

on the custom save method(the same line as cache.delete()) And it worked.. But what I want is just deleting a certain cache not everything that is why .clear() is not acceptable

Dean Christian Armada
  • 6,724
  • 9
  • 67
  • 116
  • http://stackoverflow.com/a/36845722/3570352 - this answer contains version updated for Django 1.7+ (tested on 1.9) – rafalmp Jul 28 '16 at 11:35

0 Answers0