Skip to content

Commit 5f15031

Browse files
authored
Fix: Signature error in plugin example(#11)
1 parent 30eb2c1 commit 5f15031

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

docs/src/en/plugin.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,15 @@ With user-defined sive python hook functions,
1313
py::function cache_free_hook;
1414
```
1515

16-
We can simulate and determine the cache eviction behavior from the python side.
16+
We can simulate and determine the cache eviction behavior from the python side.
17+
18+
Here is the signature requirement for these hook functions.
19+
20+
```python
21+
def cache_init_hook(ccparams: CommonCacheParams) -> CustomizedCacheData: ...
22+
def cache_hit_hook(data: CustomizedCacheData, req: Request) -> None: ...
23+
def cache_miss_hook(data: CustomizedCacheData, req: Request) -> None: ...
24+
def cache_eviction_hook(data: CustomizedCacheData, req: Request) -> int | str: ...
25+
def cache_remove_hook(data: CustomizedCacheData, obj_id: int | str) ->: ...
26+
def cache_free_hook(data: CustomizedCacheData) ->: ...
27+
```

examples/plugin_cache.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def cache_remove(self, obj_id):
2525
def cache_init_hook(common_cache_params: CommonCacheParams):
2626
return StandaloneLRU()
2727

28-
def cache_hit_hook(cache, obj_id):
29-
cache.cache_hit(obj_id)
28+
def cache_hit_hook(cache, request: Request):
29+
cache.cache_hit(request.obj_id)
3030

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

34-
def cache_eviction_hook(cache):
34+
def cache_eviction_hook(cache, request: Request):
3535
return cache.cache_eviction()
3636

3737
def cache_remove_hook(cache, obj_id):
@@ -41,7 +41,7 @@ def cache_free_hook(cache):
4141
cache.cache_data.clear()
4242

4343
plugin_lru_cache = PluginCache(
44-
cache_size=1024*1024,
44+
cache_size=1024,
4545
cache_init_hook=cache_init_hook,
4646
cache_hit_hook=cache_hit_hook,
4747
cache_miss_hook=cache_miss_hook,
@@ -50,7 +50,7 @@ def cache_free_hook(cache):
5050
cache_free_hook=cache_free_hook,
5151
cache_name="CustomizedLRU")
5252

53-
ref_lru_cache = LRU(cache_size=1024*1024)
53+
ref_lru_cache = LRU(cache_size=1024)
5454

5555
reader = SyntheticReader(
5656
num_of_req=100000,

0 commit comments

Comments
 (0)