Skip to content

Commit

Permalink
Flush the TOML parsing cache for every incoming request
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierphi committed Apr 20, 2024
1 parent fcfc383 commit 9e76add
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
10 changes: 0 additions & 10 deletions myresume/apps.py

This file was deleted.

2 changes: 1 addition & 1 deletion myresume/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def projects(lang: "Lang") -> "ProjectsData":


def clear_cache() -> None:
for cached_function in (pages, i18n, document, bio, tech, job_experience):
for cached_function in (pages, i18n, document, bio, tech, projects, job_experience):
cached_function.cache_clear() # type: ignore
_logger.info("DB cache cleared")

Expand Down
17 changes: 17 additions & 0 deletions myresume/middlewares.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import TYPE_CHECKING, Callable

from .db import clear_cache

if TYPE_CHECKING:
from django.http import HttpRequest, HttpResponse


class TOMLCacheClearingMiddleware:
def __init__(self, get_response: Callable[["HttpRequest"], "HttpResponse"]):
self.get_response = get_response

def __call__(self, request: "HttpRequest") -> "HttpResponse":
# We flush the TOML parsing cache on each request
clear_cache()

return self.get_response(request)
5 changes: 4 additions & 1 deletion myresume/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@

MIDDLEWARE = []
if DEBUG:
MIDDLEWARE += ["django_browser_reload.middleware.BrowserReloadMiddleware"]
MIDDLEWARE += [
"django_browser_reload.middleware.BrowserReloadMiddleware",
"myresume.middlewares.TOMLCacheClearingMiddleware",
]

ROOT_URLCONF = "myresume.urls"

Expand Down

0 comments on commit 9e76add

Please sign in to comment.