Skip to content

Fix: Complete frequently used cache eviction algos #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,5 @@ sftp-config.json

# Custom files
CMakeFiles/*
*.pyc
*.pyc
!scripts/smart_build.py
4 changes: 2 additions & 2 deletions benchmark/simulation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" Benchmark the simulation performance of the library.
"""Benchmark the simulation performance of the library.

This module contains benchmarks for various components of the library,
including request processing times, memory usage, and overall throughput.
"""
"""
13 changes: 9 additions & 4 deletions examples/plugin_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import OrderedDict
from libcachesim import PluginCache, CommonCacheParams, Request, SyntheticReader, LRU


class StandaloneLRU:
def __init__(self):
self.cache_data = OrderedDict()
Expand All @@ -25,21 +26,27 @@ def cache_remove(self, obj_id):
def cache_init_hook(common_cache_params: CommonCacheParams):
return StandaloneLRU()


def cache_hit_hook(cache, request: Request):
cache.cache_hit(request.obj_id)


def cache_miss_hook(cache, request: Request):
cache.cache_miss(request.obj_id, request.obj_size)


def cache_eviction_hook(cache, request: Request):
return cache.cache_eviction()


def cache_remove_hook(cache, obj_id):
cache.cache_remove(obj_id)


def cache_free_hook(cache):
cache.cache_data.clear()


plugin_lru_cache = PluginCache(
cache_size=1024,
cache_init_hook=cache_init_hook,
Expand All @@ -48,7 +55,8 @@ def cache_free_hook(cache):
cache_eviction_hook=cache_eviction_hook,
cache_remove_hook=cache_remove_hook,
cache_free_hook=cache_free_hook,
cache_name="CustomizedLRU")
cache_name="CustomizedLRU",
)

ref_lru_cache = LRU(cache_size=1024)

Expand All @@ -67,6 +75,3 @@ def cache_free_hook(cache):
assert plugin_hit == ref_hit, f"Cache hit mismatch: {plugin_hit} != {ref_hit}"

print("All requests processed successfully. Plugin cache matches reference LRU cache.")



24 changes: 24 additions & 0 deletions libcachesim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
# Optimal algorithms
Belady,
BeladySize,
# Probabilistic algorithms
LRUProb,
FlashProb,
# Size-based algorithms
Size,
GDSF,
# Hyperbolic algorithms
Hyperbolic,
# Extra deps
ThreeLCache,
GLCache,
LRB,
# Plugin cache
PluginCache,
)
Expand Down Expand Up @@ -81,6 +93,18 @@
# Optimal algorithms
"Belady",
"BeladySize",
# Probabilistic algorithms
"LRUProb",
"FlashProb",
# Size-based algorithms
"Size",
"GDSF",
# Hyperbolic algorithms
"Hyperbolic",
# Extra deps
"ThreeLCache",
"GLCache",
"LRB",
# Plugin cache
"PluginCache",
# Readers and analyzers
Expand Down
1 change: 0 additions & 1 deletion libcachesim/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def create_zipf_requests(
start_obj_id: int = 0,
seed: int | None = None,
) -> Iterator[Request]: ...

def create_uniform_requests(
num_objects: int,
num_requests: int,
Expand Down
Loading
Loading