This commit is contained in:
@@ -1,10 +1,3 @@
|
||||
"""Valkey session cache. Never the source of truth: every failure degrades to a miss.
|
||||
|
||||
Keys: session:<sha256(token) hex>
|
||||
Value: JSON {"user": {...}, "expires_at": "..."} - a valid session
|
||||
"revoked" - tombstone written by logout
|
||||
Entry TTL = min(time left in the session, SESSION_CACHE_MAX_SECONDS).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
@@ -45,7 +38,6 @@ class SessionCache:
|
||||
return self._client is not None and time.monotonic() >= self._down_until
|
||||
|
||||
def _failed(self, op: str, exc: Exception) -> None:
|
||||
# Circuit breaker: one slow failure, then skip the cache for a few seconds.
|
||||
self._down_until = time.monotonic() + config.CACHE_RETRY_AFTER
|
||||
logger.warning("cache %s failed (%s); bypassing cache for %.0fs", op, type(exc).__name__, config.CACHE_RETRY_AFTER)
|
||||
|
||||
@@ -69,7 +61,6 @@ class SessionCache:
|
||||
return None
|
||||
|
||||
async def put(self, token_hash: bytes, entry: dict, ttl_seconds: int) -> None:
|
||||
"""Fill after a PostgreSQL read. NX: never overwrite a logout tombstone."""
|
||||
ttl = min(ttl_seconds, config.SESSION_CACHE_MAX_SECONDS)
|
||||
if ttl <= 0 or not self._usable():
|
||||
return
|
||||
@@ -79,9 +70,6 @@ class SessionCache:
|
||||
self._failed("set", exc)
|
||||
|
||||
async def revoke(self, token_hash: bytes, ttl_seconds: int) -> None:
|
||||
"""Tombstone instead of DEL: a concurrent fill that read PostgreSQL before the
|
||||
revoke cannot re-insert the session afterwards (its SET NX loses).
|
||||
Tried even while the breaker is open: logout is rare and correctness matters more."""
|
||||
if self._client is None:
|
||||
return
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user