mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-12 20:45:20 +02:00
feat(etl-cache): add eviction policy
This commit is contained in:
parent
758da06c4f
commit
7ad39fd995
1 changed files with 28 additions and 0 deletions
28
surfsense_backend/app/etl_pipeline/cache/eviction/policy.py
vendored
Normal file
28
surfsense_backend/app/etl_pipeline/cache/eviction/policy.py
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
"""Pure selection rules for which cached entries to drop."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
||||
from app.etl_pipeline.cache.schemas import EvictionCandidate
|
||||
|
||||
|
||||
def select_over_budget(
|
||||
coldest_first: Iterable[EvictionCandidate],
|
||||
*,
|
||||
current_total_bytes: int,
|
||||
max_total_bytes: int,
|
||||
) -> list[EvictionCandidate]:
|
||||
"""Pick coldest entries until the footprint drops under the budget."""
|
||||
bytes_to_free = current_total_bytes - max_total_bytes
|
||||
if bytes_to_free <= 0:
|
||||
return []
|
||||
|
||||
chosen: list[EvictionCandidate] = []
|
||||
bytes_freed = 0
|
||||
for candidate in coldest_first:
|
||||
if bytes_freed >= bytes_to_free:
|
||||
break
|
||||
chosen.append(candidate)
|
||||
bytes_freed += candidate.size_bytes
|
||||
return chosen
|
||||
Loading…
Add table
Add a link
Reference in a new issue