libCacheSim Python Binding
libCacheSim is fast with the features from underlying libCacheSim lib:
- High performance - over 20M requests/sec for a realistic trace replay
- High memory efficiency - predictable and small memory footprint
- Parallelism out-of-the-box - uses the many CPU cores to speed up trace analysis and cache simulations
libCacheSim is flexible and easy to use with:
- Seamless integration with open-source cache dataset consisting of thousands traces hosted on S3
- High-throughput simulation with the underlying libCacheSim lib
- Detailed cache requests and other internal data control
- Customized plugin cache development without any compilation
Installation
Quick Install
Binary installers for the latest released version are available at the Python Package Index (PyPI).
pip install libcachesim
Visit our documentation to learn more.
Installation from sources
If there are no wheels suitable for your environment, consider building from source.
git clone https://github.com/cacheMon/libCacheSim-python.git
cd libCacheSim-python
bash scripts/install.sh
Run all tests to ensure the package works.
python -m pytest tests/
Quick Start
Cache Simulation
With libcachesim installed, you can start cache simulation for some eviction algorithm and cache traces:
import libcachesim as lcs
# Step 1: Open a trace hosted on S3 (find more via https://github.com/cacheMon/cache_dataset)
URI = "s3://cache-datasets/cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
reader = lcs.TraceReader(
trace = URI,
trace_type = lcs.TraceType.ORACLE_GENERAL_TRACE,
reader_init_params = lcs.ReaderInitParam(ignore_obj_size=False)
)
# Step 2: Initialize cache
# Note: cache_size as float (0.1) means 10% of the reader's total working set size in bytes.
# To specify an absolute size, pass an integer (e.g., 1024*1024 for 1MB).
cache = lcs.S3FIFO(
cache_size=0.1, # 0.1 = 10% of trace's working set size (requires reader parameter)
# Cache specific parameters
small_size_ratio=0.2,
ghost_size_ratio=0.8,
move_to_main_threshold=2,
reader=reader, # Required when cache_size is a float ratio
)
# Step 3: Process entire trace efficiently (C++ backend)
req_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
# Step 3.1: Process the first 1000 requests
# Note: cache_size as float means a ratio of the working set size (requires reader parameter)
cache = lcs.S3FIFO(
cache_size=0.1, # 10% of trace's working set size
# Cache specific parameters
small_size_ratio=0.2,
ghost_size_ratio=0.8,
move_to_main_threshold=2,
reader=reader, # Required when cache_size is a float ratio
)
req_miss_ratio, byte_miss_ratio = cache.process_trace(reader, start_req=0, max_req=1000)
print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
Plugin System
libCacheSim allows you to develop your own cache eviction algorithms and test them via the plugin system without any C/C++ compilation required.
Plugin Cache Overview
The PluginCache allows you to define custom caching behavior through Python callback functions. You need to implement these callback functions:
| Function | Signature | Description |
|---|---|---|
init_hook |
(common_cache_params: CommonCacheParams) -> Any |
Initialize your data structure |
hit_hook |
(data: Any, request: Request) -> None |
Handle cache hits |
miss_hook |
(data: Any, request: Request) -> None |
Handle cache misses |
eviction_hook |
(data: Any, request: Request) -> int |
Return object ID to evict |
remove_hook |
(data: Any, obj_id: int) -> None |
Clean up when object removed |
free_hook |
(data: Any) -> None |
[Optional] Final cleanup |
Example: Implementing LRU via Plugin System
from collections import OrderedDict
from typing import Any
from libcachesim import PluginCache, LRU, CommonCacheParams, Request, SyntheticReader
def init_hook(_: CommonCacheParams) -> Any:
return OrderedDict()
def hit_hook(data: Any, req: Request) -> None:
data.move_to_end(req.obj_id, last=True)
def miss_hook(data: Any, req: Request) -> None:
data.__setitem__(req.obj_id, req.obj_size)
def eviction_hook(data: Any, _: Request) -> int:
return data.popitem(last=False)[0]
def remove_hook(data: Any, obj_id: int) -> None:
data.pop(obj_id, None)
def free_hook(data: Any) -> None:
data.clear()
plugin_lru_cache = PluginCache(
cache_size=128,
cache_init_hook=init_hook,
cache_hit_hook=hit_hook,
cache_miss_hook=miss_hook,
cache_eviction_hook=eviction_hook,
cache_remove_hook=remove_hook,
cache_free_hook=free_hook,
cache_name="Plugin_LRU",
)
reader = SyntheticReader(
num_objects=1000, num_of_req=10000, obj_size=1, alpha=1.0, dist="zipf"
)
req_miss_ratio, byte_miss_ratio = plugin_lru_cache.process_trace(reader)
By defining custom hook functions for cache initialization, hit, miss, eviction, removal, and cleanup, users can easily prototype and test their own cache eviction algorithms.
Getting Help
- Check project documentation for detailed guides
- Open issues on GitHub
- Review examples in the main repository
Reference
Please cite the following papers if you use libCacheSim.
@inproceedings{yang2020-workload,
author = {Juncheng Yang and Yao Yue and K. V. Rashmi},
title = {A large-scale analysis of hundreds of in-memory cache clusters at Twitter},
booktitle = {14th USENIX Symposium on Operating Systems Design and Implementation (OSDI 20)},
year = {2020},
isbn = {978-1-939133-19-9},
pages = {191--208},
url = {https://www.usenix.org/conference/osdi20/presentation/yang},
publisher = {USENIX Association},
}
@inproceedings{yang2023-s3fifo,
title = {FIFO Queues Are All You Need for Cache Eviction},
author = {Juncheng Yang and Yazhuo Zhang and Ziyue Qiu and Yao Yue and K.V. Rashmi},
isbn = {9798400702297},
publisher = {Association for Computing Machinery},
booktitle = {Symposium on Operating Systems Principles (SOSP'23)},
pages = {130–149},
numpages = {20},
year={2023}
}
@inproceedings{yang2023-qdlp,
author = {Juncheng Yang and Ziyue Qiu and Yazhuo Zhang and Yao Yue and K.V. Rashmi},
title = {FIFO Can Be Better than LRU: The Power of Lazy Promotion and Quick Demotion},
year = {2023},
isbn = {9798400701955},
publisher = {Association for Computing Machinery},
doi = {10.1145/3593856.3595887},
booktitle = {Proceedings of the 19th Workshop on Hot Topics in Operating Systems (HotOS23)},
pages = {70–79},
numpages = {10},
}
If you used libCacheSim in your research, please cite the above papers.
License
See LICENSE for details.
Metadata
Release files for libcachesim 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| libcachesim-0.3.5.tar.gz | 81.3 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| libcachesim-0.3.5-cp313-cp313-manylinux_2_34_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.34+ x86-64 | Details |
| libcachesim-0.3.5-cp313-cp313-macosx_15_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 15.0+ ARM64 | Details |
| libcachesim-0.3.5-cp312-cp312-manylinux_2_34_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.34+ x86-64 | Details |
| libcachesim-0.3.5-cp312-cp312-macosx_15_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 15.0+ ARM64 | Details |
| libcachesim-0.3.5-cp311-cp311-manylinux_2_34_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.34+ x86-64 | Details |
| libcachesim-0.3.5-cp311-cp311-macosx_15_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 15.0+ ARM64 | Details |
| libcachesim-0.3.5-cp310-cp310-manylinux_2_34_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.34+ x86-64 | Details |
| libcachesim-0.3.5-cp310-cp310-macosx_15_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 15.0+ ARM64 | Details |
Total release size: 142.2 MB
Release files / libcachesim-0.3.5.tar.gz
| Download URL | libcachesim-0.3.5.tar.gz |
|---|---|
| Size | 81.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a1512046ab45bc0e5f0a81e5673cd02209477ffeefcb17a05fa714a06371abfb
|
|
BLAKE2b-256 checksum How to use checksums |
afc445905a3f8bc84593550af94a882795e78f2f2b200f90737ff8e4bdb71d5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / libcachesim-0.3.5-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | libcachesim-0.3.5-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 10.5 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
3210f2b2aee58f5ae49b6102c885cf5bc623ac80e4b5f16df42cdb2076513739
|
|
BLAKE2b-256 checksum How to use checksums |
76c0c60e9e59d029a77bb345d54130ef087559d6dd05470b416ee3befd6d017f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / libcachesim-0.3.5-cp313-cp313-macosx_15_0_arm64.whl
| Download URL | libcachesim-0.3.5-cp313-cp313-macosx_15_0_arm64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.13 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9dcbef799954594534be3ba3d7c2b28dacc101f9703456a1afd1d692ded4c580
|
|
BLAKE2b-256 checksum How to use checksums |
2591489c3a1ea35c18f4958b10d44283f101af4cf876e38c02fec31af842158c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / libcachesim-0.3.5-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | libcachesim-0.3.5-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 10.5 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
c51bec8f990bc52a2f21bd6667591d94170b1c87cc22e662ae1538ce2327d5fc
|
|
BLAKE2b-256 checksum How to use checksums |
509537520141dd2c4e7ab5dc5d603be2fc038af11c225940d2bbbc357b2a8244
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / libcachesim-0.3.5-cp312-cp312-macosx_15_0_arm64.whl
| Download URL | libcachesim-0.3.5-cp312-cp312-macosx_15_0_arm64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.12 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
925e45987b82a8f72f0f36d7c339be24cd6762a4a9e065fd2b06db2d161c8ff0
|
|
BLAKE2b-256 checksum How to use checksums |
317b4ed0d52bd23fc46bd01961cb2e90f5d167e172e201af2b8be2c17b60a4e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / libcachesim-0.3.5-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | libcachesim-0.3.5-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 10.5 MB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
b257f5917adc1b4eb14de8583bb8381d502443ade8b593dec71003aa57fbfe6a
|
|
BLAKE2b-256 checksum How to use checksums |
f30525689b226e2cb4b99d882748065175891ac3605ebb2641b35d76c09000c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / libcachesim-0.3.5-cp311-cp311-macosx_15_0_arm64.whl
| Download URL | libcachesim-0.3.5-cp311-cp311-macosx_15_0_arm64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.11 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
29dca26c332232781b5f24deeefa37f0abe2ec52a392551fbce2e9c020636f0f
|
|
BLAKE2b-256 checksum How to use checksums |
3cd15cf5b515f9c2210b6b3d85dfabd7b39ac2db159ba73f4a0582ea1d5b3fc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / libcachesim-0.3.5-cp310-cp310-manylinux_2_34_x86_64.whl
| Download URL | libcachesim-0.3.5-cp310-cp310-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 10.5 MB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
cd34e913c52a0ce8492f5675624c05855219cb06f049589f7257a196debaa9ec
|
|
BLAKE2b-256 checksum How to use checksums |
f2d87af18bb93d29580dc0f6aed06f7ce7fb6e197f9f85b15aa24a257b546602
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / libcachesim-0.3.5-cp310-cp310-macosx_15_0_arm64.whl
| Download URL | libcachesim-0.3.5-cp310-cp310-macosx_15_0_arm64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.10 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
2fcaa1ca428bf00444b1b530a30b2574d4466c93275aa34958b1792fc612707a
|
|
BLAKE2b-256 checksum How to use checksums |
4af398a42d6253ad25395df1e0cd97fd8ff07380fee0c005732b40f1e3ee82f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency log