mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
web: DRY Step 5 and alternatives (partial+macro), centralize start_ctx/owned_set, adopt builder_*
This commit is contained in:
parent
fe9aabbce9
commit
014bcc37b7
24 changed files with 1200 additions and 766 deletions
25
code/web/services/alts_utils.py
Normal file
25
code/web/services/alts_utils.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Dict, Tuple
|
||||
import time as _t
|
||||
|
||||
# Lightweight in-memory TTL cache for alternatives fragments
|
||||
_ALTS_CACHE: Dict[Tuple[str, str, bool], Tuple[float, str]] = {}
|
||||
_ALTS_TTL_SECONDS = 60.0
|
||||
|
||||
|
||||
def get_cached(key: tuple[str, str, bool]) -> str | None:
|
||||
try:
|
||||
ts, html = _ALTS_CACHE.get(key, (0.0, ""))
|
||||
if ts and (_t.time() - ts) < _ALTS_TTL_SECONDS:
|
||||
return html
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def set_cached(key: tuple[str, str, bool], html: str) -> None:
|
||||
try:
|
||||
_ALTS_CACHE[key] = (_t.time(), html)
|
||||
except Exception:
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue