[Feat] Add is_user_level property and cache_salt param to EvictionPolicy#3032
Conversation
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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5a8a031. Configure here.
| self, | ||
| expected_ratio: float, | ||
| key_eligible_filter: Callable[[ObjectKey], bool] | None = None, | ||
| cache_salt: str | None = None, |
There was a problem hiding this comment.
Modified public method missing required docstring
Medium Severity
The get_eviction_actions method in NoOpEvictionPolicy is modified (new cache_salt parameter added) but has no docstring. Per AGENTS.md, all new/modified public functions require complete docstrings covering what the function does, arguments, return values, and exceptions. The LRUEvictionPolicy counterpart has a full docstring, so this is inconsistent.
Triggered by project rule: LMCache Code Review Style Guide
Reviewed by Cursor Bugbot for commit 5a8a031. Configure here.
| Default is False. Subclasses that support per-user eviction | ||
| (e.g., ``UserLRUEvictionPolicy``) should override to return True. | ||
| """ | ||
| return False |
There was a problem hiding this comment.
New features lack any corresponding tests
Medium Severity
The new is_user_level property and cache_salt parameter have zero test coverage. No tests verify that LRUEvictionPolicy and NoOpEvictionPolicy return False for is_user_level, nor that they accept and correctly ignore cache_salt. Per the project rules, new features require corresponding tests — this is classified as an error-level issue.
Additional Locations (1)
Triggered by project rule: LMCache Code Review Style Guide
Reviewed by Cursor Bugbot for commit 5a8a031. Configure here.
There was a problem hiding this comment.
Code Review
This pull request introduces infrastructure for per-user eviction by adding an is_user_level property to the EvictionPolicy base class and extending the get_eviction_actions method signature to include a cache_salt parameter. These changes are applied to the base class and the LRU and Noop policy implementations. Feedback highlights that the documentation in eviction.py references a cache_salt attribute on ObjectKey that does not currently exist, which should be corrected to ensure consistency and prevent potential errors.
| skipped. This is useful for skipping locked keys that | ||
| cannot be deleted. | ||
| cache_salt: When set, scope eviction to keys belonging to this | ||
| salt only (identified by ``ObjectKey.cache_salt``). When |
There was a problem hiding this comment.
The docstring refers to ObjectKey.cache_salt, but the ObjectKey class (defined in lmcache/v1/distributed/api.py) does not currently have a cache_salt attribute. This will lead to confusion or AttributeError when implementing policies that attempt to access this field. Please ensure ObjectKey is updated or correct the documentation reference.
| """ | ||
|
|
||
| @property | ||
| def is_user_level(self) -> bool: |
There was a problem hiding this comment.
nit: change to "support_isolation" maybe?
Signed-off-by: royyhuang <roy.y.huang@gmail.com>
…icy (LMCache#3032) * [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> * address comments Signed-off-by: royyhuang <roy.y.huang@gmail.com> --------- Signed-off-by: royyhuang <royyhuang@gmail.com> Signed-off-by: royyhuang <roy.y.huang@gmail.com>


Summary
is_user_levelproperty toEvictionPolicybase class (defaultFalse)cache_salt: str | None = Noneparameter toget_eviction_actions()LRUEvictionPolicyandNoOpEvictionPolicyaccept and ignorecache_saltWhy
The eviction controller needs a way to distinguish aggregate-level policies (LRU) from per-user-level policies (UserLRU, coming in a follow-up PR) without
isinstancechecks.is_user_levelis the extension point — future policies override it toTrueand use thecache_saltparameter for scoped eviction.Changes
eviction.pyis_user_levelproperty (defaultFalse);cache_saltparam onget_eviction_actions()lru.pycache_saltnoop.pycache_saltTest plan
Context
PR4 of the per-user L2 quota feature. See design doc:
docs/design/l2_adapters/l2_per_user_quota.mdNote
Low Risk
Low risk: this is a backward-compatible interface extension (new property + optional parameter) with no behavior change in existing policies, which simply accept/ignore
cache_salt.Overview
Adds an isolation-capability extension point to
EvictionPolicyvia a newsupport_isolationproperty (defaultFalse) and an optionalcache_saltargument onget_eviction_actions()for scoping evictions.Updates
LRUEvictionPolicyandNoOpEvictionPolicyto accept the newcache_saltparameter (documented as ignored), keeping current eviction behavior unchanged while enabling future per-salt/user eviction policies.Reviewed by Cursor Bugbot for commit 762966e. Bugbot is set up for automated code reviews on this repo. Configure here.