-
-
Save jTiKey/b0c5aa24e624985b9b320a0faa136bc2 to your computer and use it in GitHub Desktop.
Expire @cache_page in django >=2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.cache import cache | |
from django.urls import reverse | |
from django.http import HttpRequest | |
from django.utils.cache import get_cache_key | |
def expire_page_cache(view, args=None): | |
""" | |
Removes cache created by cache_page functionality. | |
Parameters are used as they are in reverse() | |
""" | |
if args is None: | |
path = reverse(view) | |
else: | |
path = reverse(view, args=args) | |
request = HttpRequest() | |
request.path = path | |
key = get_cache_key(request) | |
if cache.has_key(key): | |
cache.delete(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment