Browser delay with changing content of the page in django admin (caching, python/django)

馋奶兔 提交于 2019-12-06 09:29:11

Yes. If you want to keep your site-wide cache on but you want to make sure that the cache gets cleared whenever your content is updated or added, you can implement a django signals to detect the add/update/delete event and clear the cache.

Django signals - https://docs.djangoproject.com/en/dev/ref/signals/

Here's a code snippet example:-

from django.db.models.signals import post_save

@receiver(post_save, sender=BlogPost)
def clear_cache(sender, instance, created, **kwargs):
    if instance.published_on is not None:
        cache.delete('feed')

In this example, whenever the BlogPost model is "saved" (added or updated), the feed key in the cache will be deleted. In your case, you will have to implement page-content (something like this cache.delete('page-content') and decide which corresponding model will be your sender that triggers the clearing of the cache when it is being saved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!