diskcache-rs 0.4.10__tar.gz → 0.4.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/actions/setup-diskcache-rs/action.yml +1 -1
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/workflows/benchmark.yml +1 -1
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/workflows/build-abi3.yml +1 -1
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/workflows/build.yml +1 -2
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/workflows/release.yml +11 -6
- diskcache_rs-0.4.12/.release-please-manifest.json +3 -0
- diskcache_rs-0.4.12/AGENTS.md +90 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/CHANGELOG.md +31 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/Cargo.lock +29 -30
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/Cargo.toml +3 -3
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/PKG-INFO +1 -1
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/eviction.rs +119 -8
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/storage/optimized_backend.rs +32 -4
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/conftest.py +9 -3
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_ci_benchmark.py +3 -1
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_performance.py +6 -2
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_special_chars_keys.py +10 -0
- diskcache_rs-0.4.10/.release-please-manifest.json +0 -3
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/actions/build-and-test/action.yml +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/pull_request_template.md +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.github/workflows/ci.yml +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.gitignore +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/.pre-commit-config.yaml +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/API_COMPATIBILITY.md +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/Dockerfile.test +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/LICENSE +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/README.md +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/batch_write_comparison.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/comprehensive_performance_test.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/detailed_profiling.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/final_performance_comparison.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/high_performance_test.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/memory_usage_test.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/micro_benchmark.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/optimization_validation_test.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/performance_comparison.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/pickle_bridge_comparison.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/precise_benchmark.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/benchmarks/set_performance_analysis.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/docker-compose.test.yml +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/examples/basic_usage.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/examples/special_chars_keys_example.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/justfile +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/pyproject.toml +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/__init__.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/__init__.pyi +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/_diskcache_rs.pyi +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/cache.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/constants.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/core.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/disk.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/djangocache.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/fast_cache.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/pickle_cache.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/recipes.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/python/diskcache_rs/rust_pickle.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/release-please-config.json +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/renovate.json +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/scripts/generate_stubs.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/scripts/sync_version.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/scripts/test-docker-network.sh +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/cache.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/error.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/lib.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/memory_cache.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/migration.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/pickle_cache.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/serialization.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/storage/tests.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/storage.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/src/utils.rs +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/__init__.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/benchmark_official.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_api_compatibility.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_basic_operations.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_batch_operations.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_compatibility.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_complete_api_gaps.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_cross_platform_network.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_diskcache_rs_persistence_suite.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_docker_network.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_fast_cache.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_full_api_compatibility.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_issue_125_djangocache_multiprocess.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_issue_17_configurable_threshold.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_issue_345_nfs_safe_sqlite.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_issue_73_deterministic_hashing.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_issue_78_expire_method.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_network_filesystem.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_pickle_cache.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_recipes_and_constants.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_rust_pickle_performance.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_version_and_disk_threshold.py +0 -0
- {diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/uv.lock +0 -0
|
@@ -20,7 +20,7 @@ jobs:
|
|
|
20
20
|
runs-on: ubuntu-latest
|
|
21
21
|
strategy:
|
|
22
22
|
matrix:
|
|
23
|
-
target: [x86_64
|
|
23
|
+
target: [x86_64]
|
|
24
24
|
steps:
|
|
25
25
|
- uses: actions/checkout@v6
|
|
26
26
|
- uses: actions/setup-python@v6
|
|
@@ -98,7 +98,6 @@ jobs:
|
|
|
98
98
|
matrix:
|
|
99
99
|
target:
|
|
100
100
|
- x86_64-unknown-linux-musl
|
|
101
|
-
- i686-unknown-linux-musl
|
|
102
101
|
steps:
|
|
103
102
|
- uses: actions/checkout@v6
|
|
104
103
|
- uses: actions/setup-python@v6
|
|
@@ -11,6 +11,11 @@ on:
|
|
|
11
11
|
- 'v*'
|
|
12
12
|
- 'diskcache_rs-v*' # Support release-please tag format
|
|
13
13
|
workflow_dispatch:
|
|
14
|
+
inputs:
|
|
15
|
+
tag_name:
|
|
16
|
+
description: Existing release tag to rebuild and republish
|
|
17
|
+
required: false
|
|
18
|
+
type: string
|
|
14
19
|
|
|
15
20
|
permissions:
|
|
16
21
|
contents: write # Required for creating releases and uploading artifacts
|
|
@@ -37,7 +42,7 @@ jobs:
|
|
|
37
42
|
# Call the build workflow to build standard wheels (only if release was created)
|
|
38
43
|
build:
|
|
39
44
|
needs: release-please
|
|
40
|
-
if: ${{ needs.release-please.outputs.release_created }}
|
|
45
|
+
if: ${{ needs.release-please.outputs.release_created || (github.event_name == 'workflow_dispatch' && inputs.tag_name != '') }}
|
|
41
46
|
uses: ./.github/workflows/build.yml
|
|
42
47
|
permissions:
|
|
43
48
|
contents: read
|
|
@@ -47,7 +52,7 @@ jobs:
|
|
|
47
52
|
# Call the ABI3 build workflow to build universal wheels (only if release was created)
|
|
48
53
|
build-abi3:
|
|
49
54
|
needs: release-please
|
|
50
|
-
if: ${{ needs.release-please.outputs.release_created }}
|
|
55
|
+
if: ${{ needs.release-please.outputs.release_created || (github.event_name == 'workflow_dispatch' && inputs.tag_name != '') }}
|
|
51
56
|
uses: ./.github/workflows/build-abi3.yml
|
|
52
57
|
permissions:
|
|
53
58
|
contents: read
|
|
@@ -57,7 +62,7 @@ jobs:
|
|
|
57
62
|
# Call the CI workflow to run tests (only if release was created)
|
|
58
63
|
test:
|
|
59
64
|
needs: release-please
|
|
60
|
-
if: ${{ needs.release-please.outputs.release_created }}
|
|
65
|
+
if: ${{ needs.release-please.outputs.release_created || (github.event_name == 'workflow_dispatch' && inputs.tag_name != '') }}
|
|
61
66
|
uses: ./.github/workflows/ci.yml
|
|
62
67
|
permissions:
|
|
63
68
|
contents: read
|
|
@@ -108,7 +113,7 @@ jobs:
|
|
|
108
113
|
name: Create GitHub Release
|
|
109
114
|
runs-on: ubuntu-latest
|
|
110
115
|
needs: [release-please, pypi-publish]
|
|
111
|
-
if: ${{ needs.release-please.outputs.release_created }}
|
|
116
|
+
if: ${{ needs.release-please.outputs.release_created || (github.event_name == 'workflow_dispatch' && inputs.tag_name != '') }}
|
|
112
117
|
permissions:
|
|
113
118
|
contents: write # Required for creating releases
|
|
114
119
|
actions: read # Required for downloading artifacts
|
|
@@ -153,8 +158,8 @@ jobs:
|
|
|
153
158
|
with:
|
|
154
159
|
artifacts: "release-artifacts/*"
|
|
155
160
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
156
|
-
tag: ${{ needs.release-please.outputs.tag_name }}
|
|
157
|
-
name: ${{ needs.release-please.outputs.tag_name }}
|
|
161
|
+
tag: ${{ inputs.tag_name || needs.release-please.outputs.tag_name }}
|
|
162
|
+
name: ${{ inputs.tag_name || needs.release-please.outputs.tag_name }}
|
|
158
163
|
body: |
|
|
159
164
|
Comparing Changes: ${{ steps.changelog.outputs.compareurl }}
|
|
160
165
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# AGENTS.md — diskcache_rs
|
|
2
|
+
|
|
3
|
+
> High-performance disk cache implemented in Rust with PyO3 Python bindings,
|
|
4
|
+
> built and shipped with maturin as the `diskcache_rs` PyPI package — a
|
|
5
|
+
> drop-in, faster alternative to the pure-Python `diskcache`.
|
|
6
|
+
> Navigation map for AI agents, not a reference manual. Follow the links; do
|
|
7
|
+
> not read everything up front.
|
|
8
|
+
|
|
9
|
+
## Build & test
|
|
10
|
+
|
|
11
|
+
This repo has a justfile — use it. Run `just --list` for the live recipe list.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
vx just dev # install + build + stubs: full dev environment setup
|
|
15
|
+
vx just build # uvx maturin develop (debug extension module)
|
|
16
|
+
vx just build-release # uvx maturin develop --release
|
|
17
|
+
vx just test # uv run python -m pytest tests/ -v
|
|
18
|
+
vx just test-cov # pytest with HTML coverage for diskcache_rs
|
|
19
|
+
vx just check # format + lint + test (the local CI equivalent)
|
|
20
|
+
vx just lint # cargo clippy -- -D warnings, then uv run ruff check .
|
|
21
|
+
vx just format # cargo fmt --all, then uv run ruff format .
|
|
22
|
+
vx just fix # clippy --fix + ruff check --fix
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Release-oriented recipes:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
vx just release # uvx maturin build --release
|
|
29
|
+
vx just release-abi3 # uvx maturin build --release --features abi3 (Python 3.8+)
|
|
30
|
+
vx just publish # release, then uvx maturin publish (needs PyPI auth)
|
|
31
|
+
vx just sync-version # scripts/sync_version.py: Cargo.toml <-> pyproject.toml
|
|
32
|
+
vx just stubs # regenerate .pyi stubs with pyo3-stubgen
|
|
33
|
+
vx just verify-stubs # confirm .pyi files land inside the built wheel
|
|
34
|
+
vx just bench # pytest -k benchmark
|
|
35
|
+
vx just bench-pickle # benchmarks/pickle_bridge_comparison.py
|
|
36
|
+
vx just audit # cargo audit
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Requires Rust 1.87+, Python 3.8+, and `uv` / `maturin`.
|
|
40
|
+
|
|
41
|
+
## Repo layout
|
|
42
|
+
|
|
43
|
+
| Path | Role |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `src/cache.rs` | Core cache implementation and the PyO3 class surface |
|
|
46
|
+
| `src/storage.rs`, `src/storage/optimized_backend.rs` | SQLite-backed persistent storage (`rusqlite`, bundled) |
|
|
47
|
+
| `src/memory_cache.rs`, `src/eviction.rs` | In-memory tier and eviction policy |
|
|
48
|
+
| `src/serialization.rs` | Serializers: `serde_json`, `bincode`, `rmp-serde`, `postcard`, `lz4_flex` |
|
|
49
|
+
| `src/pickle_cache.rs` | Pickle-compatible values via the Rust pickle bridge |
|
|
50
|
+
| `src/migration.rs` | Import/migration path from the pure-Python `diskcache` |
|
|
51
|
+
| `src/error.rs`, `src/utils.rs` | Error types and helpers (`blake3`, `dashmap`, `parking_lot`) |
|
|
52
|
+
| `python/diskcache_rs/` | Python package wrapper: `cache.py`, `core.py`, `disk.py`, `fast_cache.py`, `pickle_cache.py`, `djangocache.py`, `recipes.py`, `constants.py`, plus `.pyi` stubs |
|
|
53
|
+
| `tests/` | Pytest suite — API-compatibility, persistence, network filesystem, NFS-safe SQLite, Django cache, performance |
|
|
54
|
+
| `benchmarks/` | Standalone performance and profiling scripts (not part of `just test`) |
|
|
55
|
+
| `examples/` | `basic_usage.py`, `special_chars_keys_example.py` |
|
|
56
|
+
| `scripts/` | `sync_version.py`, `generate_stubs.py`, `test-docker-network.sh` |
|
|
57
|
+
| `API_COMPATIBILITY.md` | Behavioural delta against upstream `diskcache` — read before changing public API |
|
|
58
|
+
| `Dockerfile.test`, `docker-compose.test.yml` | Containerised network-filesystem tests |
|
|
59
|
+
|
|
60
|
+
## Release
|
|
61
|
+
|
|
62
|
+
- release-please drives versioning from Conventional Commits on `main`
|
|
63
|
+
(`release-please-config.json`). `.release-please-manifest.json` is the single
|
|
64
|
+
source of version truth.
|
|
65
|
+
- `feat:` → minor, `fix:` → patch, `chore:`/`docs:`/`ci:` → **no release**.
|
|
66
|
+
- Use `chore:`/`docs:` for config and doc work so release-please does not cut a
|
|
67
|
+
valueless version.
|
|
68
|
+
- Merging the release PR triggers `.github/workflows/release.yml`, which calls
|
|
69
|
+
`build.yml` and `build-abi3.yml` to produce both wheel flavours, then
|
|
70
|
+
publishes to PyPI and creates the GitHub release.
|
|
71
|
+
- `Cargo.toml` and `pyproject.toml` must carry the same version —
|
|
72
|
+
`just sync-version` is the supported way to reconcile them.
|
|
73
|
+
|
|
74
|
+
## Do / Don't
|
|
75
|
+
|
|
76
|
+
- **Do** keep the two wheels working: any new PyO3 surface must build under
|
|
77
|
+
both the default and the `abi3` (`abi3-py38`) feature.
|
|
78
|
+
- **Do** regenerate stubs (`just stubs`) and confirm them in the wheel
|
|
79
|
+
(`just verify-stubs`) after changing the Rust API.
|
|
80
|
+
- **Do** check `API_COMPATIBILITY.md` before changing anything the pure-Python
|
|
81
|
+
`diskcache` also exposes.
|
|
82
|
+
- **Don't** edit `python/diskcache_rs/*.pyi` by hand — they are generated.
|
|
83
|
+
- **Don't** hardcode an exact version in tests (`assert __version__ == "X.Y.Z"`)
|
|
84
|
+
— release-please bumps will break it. Use `>=` or read package metadata.
|
|
85
|
+
`tests/test_version_and_disk_threshold.py` already depends on this.
|
|
86
|
+
- **Don't** add `CLAUDE.md` / `GEMINI.md` / `CURSOR.md` / `ANTHROPIC.md` /
|
|
87
|
+
`OPENAI.md` / `COPILOT.md` / `CODEBUDDY.md` / `.cursorrules` / `.clinerules` /
|
|
88
|
+
`.windsurfrules` at the root. This file is the only agent contract file.
|
|
89
|
+
- **Don't** commit build artifacts to the repo root (`target/`, `dist/`,
|
|
90
|
+
`htmlcov/`, `coverage.json`, `*.so`, `*.pyd`).
|
|
@@ -4,6 +4,37 @@
|
|
|
4
4
|
|
|
5
5
|
- sync Cargo.toml version with .cz.toml and update CHANGELOG for v0.4.0
|
|
6
6
|
|
|
7
|
+
## [0.4.12](https://github.com/loonghao/diskcache_rs/compare/diskcache_rs-v0.4.11...diskcache_rs-v0.4.12) (2026-10-14)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* clear frequency-0 bucket in LfuEviction::on_access ([#149](https://github.com/loonghao/diskcache_rs/issues/149)) ([9cd0c23](https://github.com/loonghao/diskcache_rs/commit/9cd0c236543970a707912114bdbd2a8c743db0b0))
|
|
13
|
+
* **deps:** update rust crate pyo3 to 0.29 ([2e355aa](https://github.com/loonghao/diskcache_rs/commit/2e355aabf3b78b83db404335d75babef4e56e689))
|
|
14
|
+
* **deps:** update rust crate rusqlite to 0.40 ([44b3a65](https://github.com/loonghao/diskcache_rs/commit/44b3a6531a41266101abef4eda4d77671339fa42))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Documentation
|
|
18
|
+
|
|
19
|
+
* add AGENTS.md agent contract ([#146](https://github.com/loonghao/diskcache_rs/issues/146)) ([d6d10bb](https://github.com/loonghao/diskcache_rs/commit/d6d10bb39707f599c722b3302eec7b9da35b905e))
|
|
20
|
+
|
|
21
|
+
## [0.4.11](https://github.com/loonghao/diskcache_rs/compare/diskcache_rs-v0.4.10...diskcache_rs-v0.4.11) (2026-05-12)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* **deps:** update rust crate lru to 0.18 ([0c0138f](https://github.com/loonghao/diskcache_rs/commit/0c0138f65f4b6d16cd664db6720f927211e10a3f))
|
|
27
|
+
* optimize sqlite inline cache index ([5a885ba](https://github.com/loonghao/diskcache_rs/commit/5a885bafa8c5b0a7653773a94f32232dc0dfd3af))
|
|
28
|
+
* strengthen sqlite multiprocess consistency ([e121661](https://github.com/loonghao/diskcache_rs/commit/e121661cc1e6d8d54f7670bd471c3da4e776fb47))
|
|
29
|
+
* support django cache and multiprocess opens ([044f244](https://github.com/loonghao/diskcache_rs/commit/044f244b817d4db5ec3fd13cdfbac21f184ac032))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Performance Improvements
|
|
33
|
+
|
|
34
|
+
* avoid pickling bytes values ([b081349](https://github.com/loonghao/diskcache_rs/commit/b081349082265683b891a96dff23258849c273bc))
|
|
35
|
+
* keep medium values inline ([62ed5e7](https://github.com/loonghao/diskcache_rs/commit/62ed5e7f986b6d52887e00c61441ee1d01150235))
|
|
36
|
+
* restore sqlite hot-read path ([2da51ee](https://github.com/loonghao/diskcache_rs/commit/2da51ee478f631941a57c344805db40495f07386))
|
|
37
|
+
|
|
7
38
|
## [0.4.10](https://github.com/loonghao/diskcache_rs/compare/diskcache_rs-v0.4.9...diskcache_rs-v0.4.10) (2026-04-15)
|
|
8
39
|
|
|
9
40
|
|
|
@@ -78,9 +78,9 @@ checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
|
|
|
78
78
|
|
|
79
79
|
[[package]]
|
|
80
80
|
name = "blake3"
|
|
81
|
-
version = "1.8.
|
|
81
|
+
version = "1.8.5"
|
|
82
82
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
83
|
-
checksum = "
|
|
83
|
+
checksum = "0aa83c34e62843d924f905e0f5c866eb1dd6545fc4d719e803d9ba6030371fce"
|
|
84
84
|
dependencies = [
|
|
85
85
|
"arrayref",
|
|
86
86
|
"arrayvec",
|
|
@@ -104,9 +104,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
|
|
104
104
|
|
|
105
105
|
[[package]]
|
|
106
106
|
name = "bytes"
|
|
107
|
-
version = "1.
|
|
107
|
+
version = "1.12.0"
|
|
108
108
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
109
|
-
checksum = "
|
|
109
|
+
checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593"
|
|
110
110
|
|
|
111
111
|
[[package]]
|
|
112
112
|
name = "cc"
|
|
@@ -126,9 +126,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
|
126
126
|
|
|
127
127
|
[[package]]
|
|
128
128
|
name = "chrono"
|
|
129
|
-
version = "0.4.
|
|
129
|
+
version = "0.4.45"
|
|
130
130
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
131
|
-
checksum = "
|
|
131
|
+
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
|
|
132
132
|
dependencies = [
|
|
133
133
|
"iana-time-zone",
|
|
134
134
|
"js-sys",
|
|
@@ -232,9 +232,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
|
|
232
232
|
|
|
233
233
|
[[package]]
|
|
234
234
|
name = "dashmap"
|
|
235
|
-
version = "6.1
|
|
235
|
+
version = "6.2.1"
|
|
236
236
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
237
|
-
checksum = "
|
|
237
|
+
checksum = "e6361d5c062261c78a176addb82d4c821ae42bed6089de0e12603cd25de2059c"
|
|
238
238
|
dependencies = [
|
|
239
239
|
"cfg-if",
|
|
240
240
|
"crossbeam-utils",
|
|
@@ -246,7 +246,7 @@ dependencies = [
|
|
|
246
246
|
|
|
247
247
|
[[package]]
|
|
248
248
|
name = "diskcache_rs"
|
|
249
|
-
version = "0.4.
|
|
249
|
+
version = "0.4.12"
|
|
250
250
|
dependencies = [
|
|
251
251
|
"anyhow",
|
|
252
252
|
"bincode",
|
|
@@ -508,15 +508,15 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
|
|
508
508
|
|
|
509
509
|
[[package]]
|
|
510
510
|
name = "libc"
|
|
511
|
-
version = "0.2.
|
|
511
|
+
version = "0.2.186"
|
|
512
512
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
513
|
-
checksum = "
|
|
513
|
+
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
|
514
514
|
|
|
515
515
|
[[package]]
|
|
516
516
|
name = "libsqlite3-sys"
|
|
517
|
-
version = "0.
|
|
517
|
+
version = "0.38.0"
|
|
518
518
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
519
|
-
checksum = "
|
|
519
|
+
checksum = "a76001fb4daed01e5f2b518aac0b4dc592e7c734da63dbffcf0c64fa612a8d0c"
|
|
520
520
|
dependencies = [
|
|
521
521
|
"cc",
|
|
522
522
|
"pkg-config",
|
|
@@ -607,9 +607,9 @@ dependencies = [
|
|
|
607
607
|
|
|
608
608
|
[[package]]
|
|
609
609
|
name = "once_cell"
|
|
610
|
-
version = "1.21.
|
|
610
|
+
version = "1.21.4"
|
|
611
611
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
612
|
-
checksum = "
|
|
612
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
613
613
|
|
|
614
614
|
[[package]]
|
|
615
615
|
name = "parking_lot"
|
|
@@ -692,9 +692,9 @@ dependencies = [
|
|
|
692
692
|
|
|
693
693
|
[[package]]
|
|
694
694
|
name = "pyo3"
|
|
695
|
-
version = "0.
|
|
695
|
+
version = "0.29.3"
|
|
696
696
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
697
|
-
checksum = "
|
|
697
|
+
checksum = "700d18fa267b73b9b521fd7e13580e2f446916f176cacee1ab63fcc8191f1655"
|
|
698
698
|
dependencies = [
|
|
699
699
|
"libc",
|
|
700
700
|
"once_cell",
|
|
@@ -706,18 +706,18 @@ dependencies = [
|
|
|
706
706
|
|
|
707
707
|
[[package]]
|
|
708
708
|
name = "pyo3-build-config"
|
|
709
|
-
version = "0.
|
|
709
|
+
version = "0.29.3"
|
|
710
710
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
711
|
-
checksum = "
|
|
711
|
+
checksum = "7b3fc0c4d08f6bb10e71fe39dfb9e2f59c6eb6854e22ec8092f50c69a4499adb"
|
|
712
712
|
dependencies = [
|
|
713
713
|
"target-lexicon",
|
|
714
714
|
]
|
|
715
715
|
|
|
716
716
|
[[package]]
|
|
717
717
|
name = "pyo3-ffi"
|
|
718
|
-
version = "0.
|
|
718
|
+
version = "0.29.3"
|
|
719
719
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
720
|
-
checksum = "
|
|
720
|
+
checksum = "dfc0b8e19df29aad7086cf977bb0c2a2f143e30567eb113e9cf72b62ca698330"
|
|
721
721
|
dependencies = [
|
|
722
722
|
"libc",
|
|
723
723
|
"pyo3-build-config",
|
|
@@ -725,9 +725,9 @@ dependencies = [
|
|
|
725
725
|
|
|
726
726
|
[[package]]
|
|
727
727
|
name = "pyo3-macros"
|
|
728
|
-
version = "0.
|
|
728
|
+
version = "0.29.3"
|
|
729
729
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
730
|
-
checksum = "
|
|
730
|
+
checksum = "6100e8a4b5eba53afaa5ed078364851a0b2499c553a44c31026b929049b49dc6"
|
|
731
731
|
dependencies = [
|
|
732
732
|
"proc-macro2",
|
|
733
733
|
"pyo3-macros-backend",
|
|
@@ -737,13 +737,12 @@ dependencies = [
|
|
|
737
737
|
|
|
738
738
|
[[package]]
|
|
739
739
|
name = "pyo3-macros-backend"
|
|
740
|
-
version = "0.
|
|
740
|
+
version = "0.29.3"
|
|
741
741
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
742
|
-
checksum = "
|
|
742
|
+
checksum = "6143877a16e82b5a727b7127ff4cd86858a24a28d745d72f43e6f227c7b1bdb3"
|
|
743
743
|
dependencies = [
|
|
744
744
|
"heck",
|
|
745
745
|
"proc-macro2",
|
|
746
|
-
"pyo3-build-config",
|
|
747
746
|
"quote",
|
|
748
747
|
"syn",
|
|
749
748
|
]
|
|
@@ -804,9 +803,9 @@ dependencies = [
|
|
|
804
803
|
|
|
805
804
|
[[package]]
|
|
806
805
|
name = "rusqlite"
|
|
807
|
-
version = "0.
|
|
806
|
+
version = "0.40.0"
|
|
808
807
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
809
|
-
checksum = "
|
|
808
|
+
checksum = "1b3492ea85308705c3a5cc24fb9b9cf77273d30590349070db42991202b214c4"
|
|
810
809
|
dependencies = [
|
|
811
810
|
"bitflags",
|
|
812
811
|
"chrono",
|
|
@@ -1061,9 +1060,9 @@ checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
|
|
|
1061
1060
|
|
|
1062
1061
|
[[package]]
|
|
1063
1062
|
name = "uuid"
|
|
1064
|
-
version = "1.23.
|
|
1063
|
+
version = "1.23.3"
|
|
1065
1064
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1066
|
-
checksum = "
|
|
1065
|
+
checksum = "144d6b123cef80b301b8f72a9e2ca4370ddec21950d0a103dd22c437006d2db7"
|
|
1067
1066
|
dependencies = [
|
|
1068
1067
|
"getrandom",
|
|
1069
1068
|
"js-sys",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "diskcache_rs"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.12"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
authors = ["longhao <hal.long@outlook.com>"]
|
|
6
6
|
description = "A high-performance disk cache implementation in Rust with Python bindings"
|
|
@@ -28,7 +28,7 @@ panic = "abort"
|
|
|
28
28
|
strip = "symbols"
|
|
29
29
|
|
|
30
30
|
[dependencies]
|
|
31
|
-
pyo3 = { version = "0.
|
|
31
|
+
pyo3 = { version = "0.29.3", features = ["extension-module"] }
|
|
32
32
|
serde = { version = "1.0", features = ["derive"] }
|
|
33
33
|
serde_json = "1.0"
|
|
34
34
|
bincode = "2.0"
|
|
@@ -36,7 +36,7 @@ rmp-serde = "1.3"
|
|
|
36
36
|
# Keep only what we actually use
|
|
37
37
|
postcard = { version = "1.1", features = ["alloc"] }
|
|
38
38
|
# SQLite for diskcache-compatible storage
|
|
39
|
-
rusqlite = { version = "0.
|
|
39
|
+
rusqlite = { version = "0.40", features = ["bundled", "blob", "chrono"] }
|
|
40
40
|
|
|
41
41
|
# tokio removed - using std::thread instead for simplicity
|
|
42
42
|
parking_lot = "0.12"
|
|
@@ -101,13 +101,15 @@ impl EvictionPolicy for LfuEviction {
|
|
|
101
101
|
let old_freq = key_to_frequency.get(key).copied().unwrap_or(0);
|
|
102
102
|
let new_freq = entry.access_count;
|
|
103
103
|
|
|
104
|
-
// Remove from old frequency bucket
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
// Remove from old frequency bucket. This must run unconditionally: a
|
|
105
|
+
// key inserted with access_count == 0 lives in bucket 0, so guarding on
|
|
106
|
+
// `old_freq > 0` would leave a stale copy behind and make
|
|
107
|
+
// `select_victims` return the same key twice. For a brand new key the
|
|
108
|
+
// lookup simply misses and this is a no-op.
|
|
109
|
+
if let Some(bucket) = frequency_order.get_mut(&old_freq) {
|
|
110
|
+
bucket.retain(|k| k != key);
|
|
111
|
+
if bucket.is_empty() {
|
|
112
|
+
frequency_order.remove(&old_freq);
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -142,7 +144,7 @@ impl EvictionPolicy for LfuEviction {
|
|
|
142
144
|
let frequency_order = self.frequency_order.read();
|
|
143
145
|
let mut victims = Vec::new();
|
|
144
146
|
|
|
145
|
-
for
|
|
147
|
+
for keys in frequency_order.values() {
|
|
146
148
|
for key in keys {
|
|
147
149
|
if victims.len() >= count {
|
|
148
150
|
break;
|
|
@@ -438,3 +440,112 @@ impl EvictionPolicy for CombinedEviction {
|
|
|
438
440
|
self.least_recently_stored.clear();
|
|
439
441
|
}
|
|
440
442
|
}
|
|
443
|
+
|
|
444
|
+
#[cfg(test)]
|
|
445
|
+
mod tests {
|
|
446
|
+
use super::*;
|
|
447
|
+
|
|
448
|
+
/// Build a cache entry carrying an explicit access count.
|
|
449
|
+
fn entry_with_access_count(key: &str, access_count: u64) -> CacheEntry {
|
|
450
|
+
let mut entry = CacheEntry::new_inline(key.to_string(), b"value".to_vec(), vec![], None);
|
|
451
|
+
entry.access_count = access_count;
|
|
452
|
+
entry
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/// A key must never appear twice in `select_victims`, even after it is
|
|
456
|
+
/// promoted out of the frequency-0 bucket.
|
|
457
|
+
#[test]
|
|
458
|
+
fn select_victims_has_no_duplicate_keys_after_frequency_zero_promotion() {
|
|
459
|
+
let policy = LfuEviction::new();
|
|
460
|
+
|
|
461
|
+
// Insert lands the key in the frequency-0 bucket (access_count == 0).
|
|
462
|
+
policy.on_insert("a", &entry_with_access_count("a", 0));
|
|
463
|
+
// A later access promotes it out of bucket 0 into bucket 1.
|
|
464
|
+
policy.on_access("a", &entry_with_access_count("a", 1));
|
|
465
|
+
|
|
466
|
+
let victims = policy.select_victims(10);
|
|
467
|
+
|
|
468
|
+
let unique: std::collections::HashSet<_> = victims.iter().collect();
|
|
469
|
+
assert_eq!(
|
|
470
|
+
unique.len(),
|
|
471
|
+
victims.len(),
|
|
472
|
+
"same key selected more than once: {victims:?}"
|
|
473
|
+
);
|
|
474
|
+
assert_eq!(victims, vec!["a".to_string()]);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/// Victims are ordered by ascending frequency, with the least frequently
|
|
478
|
+
/// used keys evicted first.
|
|
479
|
+
#[test]
|
|
480
|
+
fn select_victims_orders_by_ascending_frequency() {
|
|
481
|
+
let policy = LfuEviction::new();
|
|
482
|
+
|
|
483
|
+
policy.on_insert("low", &entry_with_access_count("low", 0));
|
|
484
|
+
policy.on_insert("mid", &entry_with_access_count("mid", 3));
|
|
485
|
+
policy.on_insert("high", &entry_with_access_count("high", 7));
|
|
486
|
+
|
|
487
|
+
let victims = policy.select_victims(10);
|
|
488
|
+
|
|
489
|
+
assert_eq!(
|
|
490
|
+
victims,
|
|
491
|
+
vec!["low".to_string(), "mid".to_string(), "high".to_string()],
|
|
492
|
+
"expected victims ordered by ascending frequency"
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/// Promotion must move a key between buckets, not copy it, so the number of
|
|
497
|
+
/// selectable victims still matches the number of tracked keys.
|
|
498
|
+
#[test]
|
|
499
|
+
fn select_victims_count_after_promotion_matches_tracked_keys() {
|
|
500
|
+
let policy = LfuEviction::new();
|
|
501
|
+
|
|
502
|
+
for key in ["a", "b", "c"] {
|
|
503
|
+
policy.on_insert(key, &entry_with_access_count(key, 0));
|
|
504
|
+
}
|
|
505
|
+
// Promote "a" and "b" out of the frequency-0 bucket.
|
|
506
|
+
policy.on_access("a", &entry_with_access_count("a", 1));
|
|
507
|
+
policy.on_access("b", &entry_with_access_count("b", 2));
|
|
508
|
+
|
|
509
|
+
// Three keys are tracked, so three distinct victims must be available.
|
|
510
|
+
let victims = policy.select_victims(3);
|
|
511
|
+
assert_eq!(
|
|
512
|
+
victims.len(),
|
|
513
|
+
3,
|
|
514
|
+
"expected 3 distinct victims, got {victims:?}"
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
let unique: std::collections::HashSet<_> = victims.iter().collect();
|
|
518
|
+
assert_eq!(unique.len(), 3, "duplicate victims returned: {victims:?}");
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/// `select_victims` never returns more keys than requested.
|
|
522
|
+
#[test]
|
|
523
|
+
fn select_victims_respects_requested_count() {
|
|
524
|
+
let policy = LfuEviction::new();
|
|
525
|
+
|
|
526
|
+
for key in ["a", "b", "c", "d"] {
|
|
527
|
+
policy.on_insert(key, &entry_with_access_count(key, 0));
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
assert_eq!(policy.select_victims(0).len(), 0);
|
|
531
|
+
assert_eq!(policy.select_victims(2).len(), 2);
|
|
532
|
+
assert_eq!(policy.select_victims(10).len(), 4);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/// A repeated access at an unchanged frequency must not duplicate the key.
|
|
536
|
+
#[test]
|
|
537
|
+
fn repeated_access_at_same_frequency_does_not_duplicate_key() {
|
|
538
|
+
let policy = LfuEviction::new();
|
|
539
|
+
|
|
540
|
+
policy.on_insert("a", &entry_with_access_count("a", 2));
|
|
541
|
+
policy.on_access("a", &entry_with_access_count("a", 2));
|
|
542
|
+
policy.on_access("a", &entry_with_access_count("a", 2));
|
|
543
|
+
|
|
544
|
+
let victims = policy.select_victims(10);
|
|
545
|
+
assert_eq!(
|
|
546
|
+
victims,
|
|
547
|
+
vec!["a".to_string()],
|
|
548
|
+
"repeated access must not duplicate the key in its bucket"
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
@@ -12,7 +12,7 @@ use std::collections::VecDeque;
|
|
|
12
12
|
use std::fs::{File, OpenOptions};
|
|
13
13
|
use std::io::{BufWriter, Write};
|
|
14
14
|
use std::path::{Path, PathBuf};
|
|
15
|
-
use std::sync::atomic::{AtomicU64, Ordering};
|
|
15
|
+
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
|
16
16
|
use std::sync::mpsc;
|
|
17
17
|
use std::sync::Arc;
|
|
18
18
|
use std::time::Duration;
|
|
@@ -48,6 +48,9 @@ pub struct OptimizedStorage {
|
|
|
48
48
|
|
|
49
49
|
// Statistics
|
|
50
50
|
stats: Arc<StorageStats>,
|
|
51
|
+
|
|
52
|
+
// Prevent close and drop from persisting the index twice.
|
|
53
|
+
closed: AtomicBool,
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
#[derive(Clone)]
|
|
@@ -349,6 +352,7 @@ impl OptimizedStorage {
|
|
|
349
352
|
write_batcher,
|
|
350
353
|
config,
|
|
351
354
|
stats: Arc::new(StorageStats::default()),
|
|
355
|
+
closed: AtomicBool::new(false),
|
|
352
356
|
};
|
|
353
357
|
|
|
354
358
|
// Load existing index from SQLite
|
|
@@ -484,11 +488,33 @@ impl OptimizedStorage {
|
|
|
484
488
|
|
|
485
489
|
/// Close background resources and flush in-memory data.
|
|
486
490
|
pub fn close_db(&self) {
|
|
491
|
+
if self.closed.swap(true, Ordering::AcqRel) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
487
495
|
self.write_batcher.shutdown();
|
|
488
496
|
|
|
489
497
|
if let Err(e) = self.flush_memory_caches() {
|
|
490
498
|
tracing::error!("Failed to flush memory caches during close: {}", e);
|
|
491
499
|
}
|
|
500
|
+
|
|
501
|
+
if let Err(e) = self.persist_index() {
|
|
502
|
+
tracing::error!("Failed to persist SQLite index during close: {}", e);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// rusqlite keeps the SQLite file handle in the Connection value. Replace
|
|
506
|
+
// it with an in-memory connection so the original database is dropped
|
|
507
|
+
// while the Python cache is being closed, including on Windows.
|
|
508
|
+
match Connection::open_in_memory() {
|
|
509
|
+
Ok(in_memory_connection) => {
|
|
510
|
+
let mut connection = self.index_db.lock();
|
|
511
|
+
let file_connection = std::mem::replace(&mut *connection, in_memory_connection);
|
|
512
|
+
drop(file_connection);
|
|
513
|
+
}
|
|
514
|
+
Err(e) => {
|
|
515
|
+
tracing::error!("Failed to release SQLite index during close: {}", e);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
492
518
|
}
|
|
493
519
|
|
|
494
520
|
/// Flush in-flight file writes. Cache entries are already persisted when set.
|
|
@@ -1141,9 +1167,11 @@ impl OptimizedStorage {
|
|
|
1141
1167
|
|
|
1142
1168
|
impl Drop for OptimizedStorage {
|
|
1143
1169
|
fn drop(&mut self) {
|
|
1144
|
-
self.
|
|
1145
|
-
|
|
1146
|
-
|
|
1170
|
+
if !self.closed.load(Ordering::Acquire) {
|
|
1171
|
+
self.write_batcher.shutdown();
|
|
1172
|
+
// Ensure index is persisted when storage is dropped
|
|
1173
|
+
let _ = self.persist_index();
|
|
1174
|
+
}
|
|
1147
1175
|
}
|
|
1148
1176
|
}
|
|
1149
1177
|
|
|
@@ -67,11 +67,13 @@ def cache(temp_cache_dir):
|
|
|
67
67
|
"""Create a cache instance for testing"""
|
|
68
68
|
from diskcache_rs import Cache
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
cache = Cache(
|
|
71
71
|
temp_cache_dir,
|
|
72
72
|
max_size=1024 * 1024, # 1MB
|
|
73
73
|
max_entries=1000,
|
|
74
74
|
)
|
|
75
|
+
yield cache
|
|
76
|
+
cache.close()
|
|
75
77
|
|
|
76
78
|
|
|
77
79
|
@pytest.fixture
|
|
@@ -79,11 +81,13 @@ def large_cache(temp_cache_dir):
|
|
|
79
81
|
"""Create a larger cache instance for performance testing"""
|
|
80
82
|
from diskcache_rs import Cache
|
|
81
83
|
|
|
82
|
-
|
|
84
|
+
cache = Cache(
|
|
83
85
|
temp_cache_dir,
|
|
84
86
|
max_size=100 * 1024 * 1024, # 100MB
|
|
85
87
|
max_entries=10000,
|
|
86
88
|
)
|
|
89
|
+
yield cache
|
|
90
|
+
cache.close()
|
|
87
91
|
|
|
88
92
|
|
|
89
93
|
@pytest.fixture
|
|
@@ -105,11 +109,13 @@ def cloud_cache(cloud_cache_dir):
|
|
|
105
109
|
"""Create a cache instance on cloud drive"""
|
|
106
110
|
from diskcache_rs import Cache
|
|
107
111
|
|
|
108
|
-
|
|
112
|
+
cache = Cache(
|
|
109
113
|
cloud_cache_dir,
|
|
110
114
|
max_size=10 * 1024 * 1024, # 10MB
|
|
111
115
|
max_entries=1000,
|
|
112
116
|
)
|
|
117
|
+
yield cache
|
|
118
|
+
cache.close()
|
|
113
119
|
|
|
114
120
|
|
|
115
121
|
@pytest.fixture
|
|
@@ -23,7 +23,9 @@ class TestCIBenchmarks:
|
|
|
23
23
|
def cache(self, temp_cache_dir):
|
|
24
24
|
"""Create a cache instance"""
|
|
25
25
|
cache_dir = os.path.join(temp_cache_dir, "test_cache")
|
|
26
|
-
|
|
26
|
+
cache = Cache(cache_dir)
|
|
27
|
+
yield cache
|
|
28
|
+
cache.close()
|
|
27
29
|
|
|
28
30
|
def test_benchmark_basic_operations(self, benchmark, cache):
|
|
29
31
|
"""Basic benchmark test for CI"""
|
|
@@ -266,7 +266,9 @@ class TestOfficialBenchmarks:
|
|
|
266
266
|
def rust_cache(self, temp_cache_dir):
|
|
267
267
|
"""Create a Rust cache instance"""
|
|
268
268
|
cache_dir = os.path.join(temp_cache_dir, "rust_cache")
|
|
269
|
-
|
|
269
|
+
cache = RustCache(cache_dir)
|
|
270
|
+
yield cache
|
|
271
|
+
cache.close()
|
|
270
272
|
|
|
271
273
|
@pytest.fixture
|
|
272
274
|
def python_cache(self, temp_cache_dir):
|
|
@@ -373,7 +375,9 @@ class TestBenchmarks:
|
|
|
373
375
|
def rust_cache(self, temp_cache_dir):
|
|
374
376
|
"""Create a Rust cache instance"""
|
|
375
377
|
cache_dir = os.path.join(temp_cache_dir, "rust_cache")
|
|
376
|
-
|
|
378
|
+
cache = RustCache(cache_dir)
|
|
379
|
+
yield cache
|
|
380
|
+
cache.close()
|
|
377
381
|
|
|
378
382
|
@pytest.fixture
|
|
379
383
|
def python_cache(self, temp_cache_dir):
|
|
@@ -29,6 +29,7 @@ class TestSpecialCharKeys:
|
|
|
29
29
|
|
|
30
30
|
assert result == value
|
|
31
31
|
assert key in cache
|
|
32
|
+
cache.close()
|
|
32
33
|
|
|
33
34
|
def test_key_with_slash(self):
|
|
34
35
|
"""Test keys containing forward slash"""
|
|
@@ -44,6 +45,7 @@ class TestSpecialCharKeys:
|
|
|
44
45
|
|
|
45
46
|
assert result == value
|
|
46
47
|
assert key in cache
|
|
48
|
+
cache.close()
|
|
47
49
|
|
|
48
50
|
def test_key_with_backslash(self):
|
|
49
51
|
"""Test keys containing backslash"""
|
|
@@ -59,6 +61,7 @@ class TestSpecialCharKeys:
|
|
|
59
61
|
|
|
60
62
|
assert result == value
|
|
61
63
|
assert key in cache
|
|
64
|
+
cache.close()
|
|
62
65
|
|
|
63
66
|
def test_key_with_dot(self):
|
|
64
67
|
"""Test keys containing dot character"""
|
|
@@ -74,6 +77,7 @@ class TestSpecialCharKeys:
|
|
|
74
77
|
|
|
75
78
|
assert result == value
|
|
76
79
|
assert key in cache
|
|
80
|
+
cache.close()
|
|
77
81
|
|
|
78
82
|
def test_key_with_multiple_special_chars(self):
|
|
79
83
|
"""Test keys with multiple special characters"""
|
|
@@ -98,6 +102,7 @@ class TestSpecialCharKeys:
|
|
|
98
102
|
result = cache.get(key)
|
|
99
103
|
assert result == value, f"Failed for key: {key}"
|
|
100
104
|
assert key in cache
|
|
105
|
+
cache.close()
|
|
101
106
|
|
|
102
107
|
def test_url_as_key(self):
|
|
103
108
|
"""Test using URLs as cache keys"""
|
|
@@ -117,6 +122,7 @@ class TestSpecialCharKeys:
|
|
|
117
122
|
|
|
118
123
|
assert result == response_data
|
|
119
124
|
assert url in cache
|
|
125
|
+
cache.close()
|
|
120
126
|
|
|
121
127
|
|
|
122
128
|
class TestAutoDeserialization:
|
|
@@ -133,6 +139,7 @@ class TestAutoDeserialization:
|
|
|
133
139
|
result = cache.get("test_key")
|
|
134
140
|
|
|
135
141
|
assert result == value
|
|
142
|
+
cache.close()
|
|
136
143
|
|
|
137
144
|
def test_json_deserialization(self):
|
|
138
145
|
"""Test automatic JSON deserialization"""
|
|
@@ -149,6 +156,7 @@ class TestAutoDeserialization:
|
|
|
149
156
|
# Should auto-deserialize JSON
|
|
150
157
|
result = cache.get("json_key")
|
|
151
158
|
assert result == json_data
|
|
159
|
+
cache.close()
|
|
152
160
|
|
|
153
161
|
def test_text_deserialization(self):
|
|
154
162
|
"""Test automatic text deserialization"""
|
|
@@ -165,6 +173,7 @@ class TestAutoDeserialization:
|
|
|
165
173
|
# Should auto-deserialize to text
|
|
166
174
|
result = cache.get("text_key")
|
|
167
175
|
assert result == text
|
|
176
|
+
cache.close()
|
|
168
177
|
|
|
169
178
|
def test_mixed_formats(self):
|
|
170
179
|
"""Test cache with mixed serialization formats"""
|
|
@@ -180,3 +189,4 @@ class TestAutoDeserialization:
|
|
|
180
189
|
assert cache.get("pickle_key") == {"type": "pickle"}
|
|
181
190
|
assert cache.get("json_key") == {"type": "json"}
|
|
182
191
|
assert cache.get("text_key") == "plain text"
|
|
192
|
+
cache.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{diskcache_rs-0.4.10 → diskcache_rs-0.4.12}/tests/test_issue_125_djangocache_multiprocess.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|