How to clear the whole cache when using django's page_cache decorator

后端 未结 3 1230
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 23:21

I\'ve got a pretty simple site where I\'m using the page_cache decorator. I have a cronjob that checks for new data and processes it if it\'s available. (This is r

3条回答
  •  误落风尘
    2021-02-03 23:50

    It's a bug #19896 that looks to be fixed in 1.6.

    If you are using an older version doing something like the following should make the clear work as expected.

    from django.db import router, transaction
    
    
    def clear_cache(the_cache):
        the_cache.clear()
        # commit the transaction
        db = router.db_for_write(the_cache.cache_model_class)
        transaction.commit_unless_managed(using=db)
    

    This just makes sure that the transaction gets committed.

提交回复
热议问题