Skip to content

Commit d3c3ad7

Browse files
authored
Complete frequently used cache eviction algos (#13)
1 parent 5f15031 commit d3c3ad7

19 files changed

+1058
-233
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,5 @@ sftp-config.json
230230

231231
# Custom files
232232
CMakeFiles/*
233-
*.pyc
233+
*.pyc
234+
!scripts/smart_build.py

benchmark/simulation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
""" Benchmark the simulation performance of the library.
1+
"""Benchmark the simulation performance of the library.
22
33
This module contains benchmarks for various components of the library,
44
including request processing times, memory usage, and overall throughput.
5-
"""
5+
"""

examples/plugin_cache.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import OrderedDict
22
from libcachesim import PluginCache, CommonCacheParams, Request, SyntheticReader, LRU
33

4+
45
class StandaloneLRU:
56
def __init__(self):
67
self.cache_data = OrderedDict()
@@ -25,21 +26,27 @@ def cache_remove(self, obj_id):
2526
def cache_init_hook(common_cache_params: CommonCacheParams):
2627
return StandaloneLRU()
2728

29+
2830
def cache_hit_hook(cache, request: Request):
2931
cache.cache_hit(request.obj_id)
3032

33+
3134
def cache_miss_hook(cache, request: Request):
3235
cache.cache_miss(request.obj_id, request.obj_size)
3336

37+
3438
def cache_eviction_hook(cache, request: Request):
3539
return cache.cache_eviction()
3640

41+
3742
def cache_remove_hook(cache, obj_id):
3843
cache.cache_remove(obj_id)
3944

45+
4046
def cache_free_hook(cache):
4147
cache.cache_data.clear()
4248

49+
4350
plugin_lru_cache = PluginCache(
4451
cache_size=1024,
4552
cache_init_hook=cache_init_hook,
@@ -48,7 +55,8 @@ def cache_free_hook(cache):
4855
cache_eviction_hook=cache_eviction_hook,
4956
cache_remove_hook=cache_remove_hook,
5057
cache_free_hook=cache_free_hook,
51-
cache_name="CustomizedLRU")
58+
cache_name="CustomizedLRU",
59+
)
5260

5361
ref_lru_cache = LRU(cache_size=1024)
5462

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

6977
print("All requests processed successfully. Plugin cache matches reference LRU cache.")
70-
71-
72-

libcachesim/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838
# Optimal algorithms
3939
Belady,
4040
BeladySize,
41+
# Probabilistic algorithms
42+
LRUProb,
43+
FlashProb,
44+
# Size-based algorithms
45+
Size,
46+
GDSF,
47+
# Hyperbolic algorithms
48+
Hyperbolic,
49+
# Extra deps
50+
ThreeLCache,
51+
GLCache,
52+
LRB,
4153
# Plugin cache
4254
PluginCache,
4355
)
@@ -81,6 +93,18 @@
8193
# Optimal algorithms
8294
"Belady",
8395
"BeladySize",
96+
# Probabilistic algorithms
97+
"LRUProb",
98+
"FlashProb",
99+
# Size-based algorithms
100+
"Size",
101+
"GDSF",
102+
# Hyperbolic algorithms
103+
"Hyperbolic",
104+
# Extra deps
105+
"ThreeLCache",
106+
"GLCache",
107+
"LRB",
84108
# Plugin cache
85109
"PluginCache",
86110
# Readers and analyzers

libcachesim/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ def create_zipf_requests(
219219
start_obj_id: int = 0,
220220
seed: int | None = None,
221221
) -> Iterator[Request]: ...
222-
223222
def create_uniform_requests(
224223
num_objects: int,
225224
num_requests: int,

0 commit comments

Comments
 (0)