Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use Django async caching
  • Loading branch information
Archmonger committed Jan 12, 2022
commit e3ba4f061fd7d6a0e3c7fa84fd1d1a88d64fa83f
8 changes: 5 additions & 3 deletions src/django_idom/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ async def web_modules_file(request: HttpRequest, file: str) -> HttpResponse:
path = IDOM_WED_MODULES_DIR.current.joinpath(*file.split("/")).absolute()
last_modified_time = os.stat(path).st_mtime
cache_key = f"django_idom:{path}"
response = idom_cache.get(cache_key, version=last_modified_time)
response = await idom_cache.aget(cache_key, version=last_modified_time)
if response is None:
response = HttpResponse(path.read_text(), content_type="text/javascript")
idom_cache.delete(cache_key)
idom_cache.set(cache_key, response, timeout=None, version=last_modified_time)
await idom_cache.adelete(cache_key)
await idom_cache.aset(
cache_key, response, timeout=None, version=last_modified_time
)
return response