Merge pull request #29066 from ankush/skip_client_cache

fix: Make client cache work without redis too
This commit is contained in:
Ankush Menat 2025-01-07 13:57:32 +05:30 committed by GitHub
commit f50518c17e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -454,7 +454,25 @@ class ClientCache:
self.cache: dict[bytes, CachedValue] = {}
self.invalidator = frappe.cache
self.invalidator_id = self.invalidator.client_id()
self.healthy = True
self.connection_retries = 0
self.invalidator_id = None
try:
self.invalidator_id = self.invalidator.client_id()
except redis.exceptions.ConnectionError:
# Redis not available, this can happen during setup/startup time
self.redis = frappe.cache
self.healthy = False
# These are local hits and misses, *not* global.
# - Local miss = not found in worker memory
# - Global miss = not found in Redis too
# These stats can be *slightly* off, these aren't guarded by a mutex.
self.hits = self.misses = 0
if not self.invalidator_id:
return
self.redis: RedisWrapper = RedisWrapper.from_url(
frappe.conf.get("redis_cache"),
@ -463,14 +481,6 @@ class ClientCache:
protocol=2,
)
self.invalidator_thread = self.run_invalidator_thread()
self.healthy = True
self.connection_retries = 0
# These are local hits and misses, *not* global.
# - Local miss = not found in worker memory
# - Global miss = not found in Redis too
# These stats can be *slightly* off, these aren't guarded by a mutex.
self.hits = self.misses = 0
def get_value(self, key):
key = self.redis.make_key(key)