Last active
May 27, 2023 00:28
-
-
Save bryanchow/4fd80e38a75be3c4e64560de2e7fd76e to your computer and use it in GitHub Desktop.
Revisions
-
bryanchow revised this gist
May 27, 2023 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # Django cache buster view # https://gist.github.com/bryanchow/4fd80e38a75be3c4e64560de2e7fd76e from django.core.cache import cache @@ -7,12 +8,12 @@ def bust_cache(request, path): """ A simple Django view that clears the cached response for the passed-in path, and redirects to that path. Example URL configuration: path("reload/<path:path>", cache_buster.bust_cache, name="bust_cache") """ -
bryanchow revised this gist
May 27, 2023 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # https://gist.github.com/bryanchow/4fd80e38a75be3c4e64560de2e7fd76e from django.core.cache import cache from django.utils.cache import get_cache_key from django.shortcuts import redirect @@ -22,4 +24,4 @@ def bust_cache(request, path): if cache.has_key(key): cache.delete(key) return redirect(path) -
bryanchow created this gist
May 27, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ from django.core.cache import cache from django.utils.cache import get_cache_key from django.shortcuts import redirect def bust_cache(request, path): """ A Django view that clears the cached response for the passed-in path, and redirects to that path. Example URL configuration: path("bust/<path:path>", cache_buster.bust_cache, name="bust_cache") """ if not path.startswith("/"): path = "/{}".format(path) request.path = path key = get_cache_key(request) if cache.has_key(key): cache.delete(key) return redirect(path)