This repository introduces a cost-aware, score-based caching policy as an extension to DiskCache. It includes benchmarking tools, synthetic workload generation, and testing suites for evaluating the performance of the new caching strategy.
-
Clone the repository:
git clone https://github.com/marwansakas/python-diskcache.git
-
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Linux/macOS .venv\Scripts\activate # On Windows
-
Install required dependencies:
pip install -r requirements-devs.txt
Run all tests, including unit and benchmark tests:
pytestRun only unit tests (excluding benchmarks):
pytest --benchmark-disableRun only the unit tests for the new policy
pytest .\marwan_testsRun a specific test file (e.g., test_score_based_cache.py):
pytest marwan_tests/test_score_based_cache.pyRun benchmark suite:
pytest marwan_tests/test_benchmarks.py --benchmark-onlyRun with debug logging (no output capture):
pytest marwan_tests/test_benchmarks.py --benchmark-only --capture=no-
Save benchmark results to file:
pytest marwan_tests/test_benchmarks.py --benchmark-only --benchmark-save=score_cache_run
-
Export results as JSON:
pytest-benchmark export score_cache_run --output benchmark_result.json
Generate graphs to analyze alpha, beta, and lambda parameter effects:
python policy_comparison/parameter_sweep_and_analysis.pyThis script runs synthetic workloads using varying parameters and produces plots:
hit_rate_vs_alpha.pngp95_latency_vs_beta.png- etc.
The script also saves detailed logs to:
parameter_sweep_results.json
To run a head-to-head comparison between the baseline (LRU) and the Score-Based policy:
python policy_comparison/vanilla_vs_extended.pyThis script will:
- Execute a common workload on both policies
- Report and compare hit rates and latency metrics
- Optionally generate visual comparisons
- The custom cache logic is implemented in
diskcache/extensions/score_based_cache.py - All tests assume DiskCache is installed and discoverable
- Make sure to clean old
__pycache__directories between changes if needed