Skip to content

feat: Add LFU Eviction Policy with LRU tie-breaking#90

Open
mariambadir wants to merge 1 commit into
vcache-project:masterfrom
mariambadir:feat/lfu-eviction-policy
Open

feat: Add LFU Eviction Policy with LRU tie-breaking#90
mariambadir wants to merge 1 commit into
vcache-project:masterfrom
mariambadir:feat/lfu-eviction-policy

Conversation

@mariambadir

Copy link
Copy Markdown

Summary

This PR adds LFUEvictionPolicy to vCache.

Motivation

Existing policies are recency-based. LFU retains high-value entries regardless of recency, improving hit rates on skewed workloads.

Changes

  • New: lfu_eviction_policy.py
  • New: tests/test_lfu_eviction_policy.py — 16 tests passing
  • Updated init.py

Tests

pytest tests/test_lfu_eviction_policy.py -v # 16 passed

Comment on lines +1 to +4
"""
Unit tests for LFUEvictionPolicy.
Run with: pytest tests/test_lfu_eviction_policy.py -v
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please move the test to the respective unit test location in tests/unit/EvictionPolicyStrategy

@luis-gasparschroeder luis-gasparschroeder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for contributing to vCache. Please move the unit test to the desired location and integrate tie-breaking into the existing LRU policy, and we can proceed with this PR.

Comment on lines +21 to +32
class LFUEvictionPolicy(EvictionPolicy):
"""
Least Frequently Used (LFU) eviction policy with LRU tie-breaking.

Tracks access_count per entry. Evicts lowest-frequency entries first.
Ties broken by last_accessed (oldest evicted first).

Args:
max_size (int): Maximum number of entries before eviction triggers.
watermark (float): Fraction of max_size that triggers eviction.
eviction_percentage (float): Fraction of max_size to evict per cycle.
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We already have an LRU policy in vcache/vcache_core/cache/eviction_policy/strategies/lru.py. Please extend that instead of implementing a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants