Skip to content

[Feat] Add is_user_level property and cache_salt param to EvictionPolicy#3032

Merged
royyhuang merged 3 commits intoLMCache:devfrom
royyhuang:feat/eviction-policy-interface
Apr 15, 2026
Merged

[Feat] Add is_user_level property and cache_salt param to EvictionPolicy#3032
royyhuang merged 3 commits intoLMCache:devfrom
royyhuang:feat/eviction-policy-interface

Conversation

@royyhuang
Copy link
Copy Markdown
Contributor

@royyhuang royyhuang commented Apr 14, 2026

Summary

  • Add is_user_level property to EvictionPolicy base class (default False)
  • Add cache_salt: str | None = None parameter to get_eviction_actions()
  • LRUEvictionPolicy and NoOpEvictionPolicy accept and ignore cache_salt

Why

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 isinstance checks. is_user_level is the extension point — future policies override it to True and use the cache_salt parameter for scoped eviction.

Changes

File Change
eviction.py is_user_level property (default False); cache_salt param on get_eviction_actions()
lru.py Accept (ignore) cache_salt
noop.py Accept (ignore) cache_salt

Test plan

  • 441 distributed tests pass
  • pre-commit clean
  • No behavioral change (all defaults are None, existing callers unaffected)

Context

PR4 of the per-user L2 quota feature. See design doc: docs/design/l2_adapters/l2_per_user_quota.md


Note

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 EvictionPolicy via a new support_isolation property (default False) and an optional cache_salt argument on get_eviction_actions() for scoping evictions.

Updates LRUEvictionPolicy and NoOpEvictionPolicy to accept the new cache_salt parameter (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.

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>
@royyhuang royyhuang requested a review from YaoJiayi as a code owner April 14, 2026 22:56
@royyhuang royyhuang requested review from ApostaC and sammshen April 14, 2026 22:58
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Triggered by project rule: LMCache Code Review Style Guide

Reviewed by Cursor Bugbot for commit 5a8a031. Configure here.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Copy link
Copy Markdown
Contributor

@ApostaC ApostaC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM!

Comment thread lmcache/v1/distributed/eviction.py Outdated
"""

@property
def is_user_level(self) -> bool:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change to "support_isolation" maybe?

@royyhuang royyhuang enabled auto-merge (squash) April 15, 2026 00:55
@github-actions github-actions Bot added the full Run comprehensive tests on this PR label Apr 15, 2026
Copy link
Copy Markdown
Contributor

@sammshen sammshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@royyhuang royyhuang merged commit 0177179 into LMCache:dev Apr 15, 2026
37 of 38 checks passed
ftian1 pushed a commit to ftian1/LMCache that referenced this pull request Apr 20, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full Run comprehensive tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants