Skip to content

Commit 5a8a031

Browse files
committed
[Feat] Add is_user_level property and cache_salt param to EvictionPolicy
Add is_user_level property to EvictionPolicy base class (default False). The eviction controller uses this to decide whether to check per-user quotas or aggregate usage — no isinstance checks needed. Add cache_salt optional parameter to get_eviction_actions(). When set, user-level policies scope eviction to keys belonging to that user. Non-user-level policies (LRU, NoOp) accept and ignore the parameter. This is an interface extension only — no new policies or behavioral changes. UserLRUEvictionPolicy (follow-up PR) will override is_user_level to return True and use cache_salt for scoped eviction. Signed-off-by: royyhuang <royyhuang@gmail.com> Signed-off-by: royyhuang <roy.y.huang@gmail.com>
1 parent cfb5c52 commit 5a8a031

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

lmcache/v1/distributed/eviction.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ class EvictionPolicy:
2727
L1EvictionPolicy and L2EvictionPolicy respectively.
2828
"""
2929

30+
@property
31+
def is_user_level(self) -> bool:
32+
"""Whether this policy supports per-user eviction.
33+
34+
When True, the eviction controller checks per-user usage and
35+
passes ``cache_salt`` to ``get_eviction_actions()`` to scope
36+
eviction to individual users. When False, the controller uses
37+
aggregate usage only.
38+
39+
Default is False. Subclasses that support per-user eviction
40+
(e.g., ``UserLRUEvictionPolicy``) should override to return True.
41+
"""
42+
return False
43+
3044
@abstractmethod
3145
def register_eviction_destination(self, destination: EvictionDestination):
3246
"""
@@ -73,6 +87,7 @@ def get_eviction_actions(
7387
self,
7488
expected_ratio: float,
7589
key_eligible_filter: Callable[[ObjectKey], bool] | None = None,
90+
cache_salt: str | None = None,
7691
) -> list[EvictionAction]:
7792
"""
7893
Get the eviction actions to evict objects from cache.
@@ -88,6 +103,11 @@ def get_eviction_actions(
88103
provided, keys for which the filter returns False will be
89104
skipped. This is useful for skipping locked keys that
90105
cannot be deleted.
106+
cache_salt: When set, scope eviction to keys belonging to this
107+
salt only (identified by ``ObjectKey.cache_salt``). When
108+
None, evict globally across all salts. Only meaningful for
109+
policies where ``is_user_level`` is True; other policies
110+
ignore this parameter.
91111
92112
Returns:
93113
list[EvictionAction]: The eviction actions to perform. Each

lmcache/v1/distributed/eviction_policy/lru.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def get_eviction_actions(
123123
self,
124124
expected_ratio: float,
125125
key_eligible_filter: Callable[[ObjectKey], bool] | None = None,
126+
cache_salt: str | None = None,
126127
) -> list[EvictionAction]:
127128
"""
128129
Get the eviction actions to evict objects from L1 cache.
@@ -137,6 +138,7 @@ def get_eviction_actions(
137138
provided, keys for which the filter returns False will be
138139
skipped. This is useful for skipping locked keys that
139140
cannot be deleted.
141+
cache_salt: Ignored by LRU policy (not user-level).
140142
141143
Returns:
142144
list[EvictionAction]: The eviction actions to perform. Each

lmcache/v1/distributed/eviction_policy/noop.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ def get_eviction_actions(
4545
self,
4646
expected_ratio: float,
4747
key_eligible_filter: Callable[[ObjectKey], bool] | None = None,
48+
cache_salt: str | None = None,
4849
) -> list[EvictionAction]:
4950
return []

0 commit comments

Comments
 (0)