refactor: split main.py i moduler (config/cache/store/services/authentik) + async dashboard (TTFB ~6ms, indhold via /dashboard-content) + TTL-cache på Authentik-læsninger
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"""Letvægts in-memory TTL-cache. Authentik-læsninger er I/O-bottleneck (ikke Python),
|
||||
så vi cacher dem kort og rydder ved skrivninger."""
|
||||
import time
|
||||
|
||||
_CACHE = {}
|
||||
|
||||
|
||||
def get(key):
|
||||
ent = _CACHE.get(key)
|
||||
if ent and ent[0] > time.monotonic():
|
||||
return ent[1]
|
||||
return None
|
||||
|
||||
|
||||
def put(key, val, ttl):
|
||||
_CACHE[key] = (time.monotonic() + ttl, val)
|
||||
|
||||
|
||||
def clear(*prefixes):
|
||||
for k in list(_CACHE):
|
||||
if not prefixes or any(k.startswith(p) for p in prefixes):
|
||||
_CACHE.pop(k, None)
|
||||
Reference in New Issue
Block a user