Skip to content

Commit c92bed3

Browse files
committed
store file contents in cache instead of response
Increase timeout
1 parent 087be86 commit c92bed3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/reactpy_django/http/views.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ async def web_modules_file(request: HttpRequest, file: str) -> HttpResponse:
2525

2626
# Fetch the file from cache, if available
2727
last_modified_time = os.stat(path).st_mtime
28-
cache_key = create_cache_key("web_module", str(path).lstrip(str(web_modules_dir)))
29-
response = await caches[REACTPY_CACHE].aget(
28+
cache_key = create_cache_key("web_modules", str(path).lstrip(str(web_modules_dir)))
29+
file_contents = await caches[REACTPY_CACHE].aget(
3030
cache_key, version=int(last_modified_time)
3131
)
32-
if response is None:
32+
if file_contents is None:
3333
async with async_open(path, "r") as fp:
34-
response = HttpResponse(await fp.read(), content_type="text/javascript")
34+
file_contents = await fp.read()
3535
await caches[REACTPY_CACHE].adelete(cache_key)
3636
await caches[REACTPY_CACHE].aset(
37-
cache_key, response, timeout=None, version=int(last_modified_time)
37+
cache_key, file_contents, timeout=604800, version=int(last_modified_time)
3838
)
39-
return response
39+
return HttpResponse(file_contents, content_type="text/javascript")
4040

4141

4242
async def view_to_component_iframe(

0 commit comments

Comments
 (0)