Skip to content

Commit c08b477

Browse files
committed
fix signal resolver issue
1 parent 9521706 commit c08b477

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

django_valkey/async_cache/cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ class AsyncValkeyCache(
88
BaseValkeyCache[AsyncDefaultClient, AValkey], AsyncBackendCommands
99
):
1010
DEFAULT_CLIENT_CLASS = "django_valkey.async_cache.client.default.AsyncDefaultClient"
11+
is_async = True

django_valkey/base.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,21 @@ async def hkeys(self, *args, **kwargs) -> list[Any]:
558558

559559
async def hexists(self, *args, **kwargs) -> bool:
560560
return await self.client.hexists(*args, **kwargs)
561+
562+
563+
# temp fix for django's #36047
564+
# TODO: remove this when it's fixed in django
565+
from django.core import signals # noqa: E402
566+
from django.core.cache import caches, close_caches # noqa: E402
567+
568+
569+
async def close_async_caches(**kwargs):
570+
for conn in caches.all(initialized_only=True):
571+
if getattr(conn, "is_async", False):
572+
await conn.aclose()
573+
else:
574+
conn.close()
575+
576+
577+
signals.request_finished.connect(close_async_caches)
578+
signals.request_finished.disconnect(close_caches)

0 commit comments

Comments
 (0)