Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
09bd180
Update changelog
awolverp Mar 31, 2025
747497b
Merge branch 'main' into morefeatures
awolverp Mar 31, 2025
eeaf184
Merge branch 'main' into morefeatures
awolverp Mar 31, 2025
7f389ca
Start rewriting
awolverp Mar 31, 2025
e3fb21c
- Rewrite the Cache class in Python
awolverp Apr 4, 2025
3bdec75
Update CHANGELOG.md
awolverp Apr 4, 2025
49c5ffd
Write a part of FIFOCache
awolverp Apr 6, 2025
aaccae2
Optimize dependencies profiles
awolverp Apr 7, 2025
e0daaba
Update tests
awolverp Apr 7, 2025
4a9d176
Update docstrings
awolverp Apr 7, 2025
08ad6d2
Optimize insert operation
awolverp Apr 7, 2025
7655a35
RRCache implemented
awolverp Apr 8, 2025
931bd0e
Fix RRCache
awolverp Apr 8, 2025
d791cc4
Fix RRCache popitem
awolverp Apr 8, 2025
82e5e10
Optimize some operations
awolverp Apr 8, 2025
5394aeb
- Rewrite LRUCache
awolverp Apr 11, 2025
83d318f
Refactor some part of LFUCache (not completed)
awolverp Apr 12, 2025
a188b58
* Refactor and optimize LFUCache
awolverp Apr 13, 2025
35cf295
Update test workflow !test
awolverp Apr 13, 2025
25420e1
Add new method `random_key` to RRCache
awolverp Apr 13, 2025
bbc71d3
Refactor a part of TTLCache
awolverp Apr 14, 2025
325c201
Support timedelta as ttl in TTLCache
awolverp Apr 14, 2025
72822dc
Fix and optimize TTLCache
awolverp Apr 15, 2025
d716b0f
Refactor pickle of TTLCache
awolverp Apr 15, 2025
e8510d8
Update TTLCache
awolverp Apr 16, 2025
b983b54
Clean code
awolverp Apr 16, 2025
325902c
Optimize TTLCache and add a new method `expire()`
awolverp Apr 16, 2025
914f754
* Write vttl policy base - not tested
awolverp Apr 16, 2025
0e836a2
* Refactor and test the VTTLCache
awolverp Apr 17, 2025
faf19ec
Update tests
awolverp Apr 17, 2025
aa2e008
Add utils and py.typed
awolverp Apr 17, 2025
6125bbd
Remove the deprecated parameter: `always_copy`
awolverp Apr 17, 2025
b8fbac2
* Rewrite a part of README.md
awolverp Apr 17, 2025
3770b26
* Rename the CacheInfo.cachememory to CacheInfo.memory
awolverp Apr 17, 2025
8530d31
Move BaseCacheImpl from _cachebox.py to _core
awolverp Apr 18, 2025
022f875
Write README.md
awolverp Apr 18, 2025
4bcb8a3
Update changelog, readme; Fix __repr__
awolverp Apr 18, 2025
65ccbac
Update test workflow
awolverp Apr 18, 2025
983eae4
Improve tests
awolverp Apr 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ name: python-test

on:
push:
branches:
- main

workflow_dispatch:

permissions:
contents: read

jobs:
test-python:
if: "contains(github.event.head_commit.message, '[run test]')"
if: "contains(github.event.head_commit.message, '!test')"
name: test ${{ matrix.python-version }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -54,7 +50,7 @@ jobs:
HYPOTHESIS_PROFILE: slow

test-os:
if: "contains(github.event.head_commit.message, '[run test]')"
if: "contains(github.event.head_commit.message, '!test')"
name: test on ${{ matrix.os }}

strategy:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/target
__pycache__
*.so
/.caches.rs
/.coverage
/.pytest_cache
/htmlcov
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v5.0.0 - Unreleased
### Added
- A new method named `random_key` added to `RRCache`.
- A new method named `expire` added to `TTLCache`.
- Some new methods added to `VTTLCache`: `expire`, `items_with_expire`.
- `TTLCache` now supports `timedelta` as ttl.
- `VTTLCache` now supports `timedelta` and `datetime` as ttl.
- A new method `copy` added to all caches.

### Changed
- The core codes (rust code) renamed from `_cachebox` to `_core`. Instead of that, all of classes
implemented in Python which are using the core's classes. This change can help to customize the alghoritms.
- Now the errors which occurred while doing `__eq__` operations will not be ignored.
- Docstrings is now more complete.
- The strictness in `__eq__` methods was reduced.
- Add more strictness for loading pickle objects.
- `LFUCache` now uses `VecDeque` instead of `Vec` (improves performance).
- The `CacheInfo.cachememory` renamed to `CacheInfo.memory`.
- *`isize` to `u64` strategy* changed in Rust.
- `__repr__` methods refactored.

### Removed
- The `n` parameter of the `LRUCache.least_recently_used` method has been removed.
- The deprecated `always_copy` parameter of the `cached` and `cachedmethod` decorators has been removed.

## 4.5.3 - 2025-03-31
### Changed
- The `cached` and `cachedmethods` decorators cached the exceptions regardless of the number of waiters. This issue has now been resolved. Thanks to @pyfreyr for the issue [#23](https://github.com/awolverp/cachebox/issues/23).
Expand Down
42 changes: 13 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 29 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cachebox"
version = "4.5.3"
version = "5.0.0"
edition = "2021"
description = "The fastest memoizing and caching Python library written in Rust"
readme = "README.md"
Expand All @@ -17,21 +17,37 @@ crate-type = ["cdylib"]
codegen-units = 1
debug = false
incremental = false
lto = "fat"
lto = true
panic = "abort"
strip = "symbols"

[dependencies]
hashbrown = { version = "^0.14", default-features = false, features=["inline-more", "raw"]}
fastrand = "^2.3"
pyo3 = { version = "0.24.0", default-features = false, features=["macros", "extension-module"] }
cfg-if = "1.0"
parking_lot_core = { version = "^0.9", default-features = false }
lock_api = { version = "^0.4", default-features = false }
fxhash = {version = "^0.2"}

[build-dependencies]
pyo3-build-config = { version = "0.24.0", features = ["resolve-config"] }
[dependencies.hashbrown]
version = "0.14.5"
default-features = false
features = ["inline-more", "raw"]

[dependencies.fastrand]
version = "2.3.0"

[dependencies.pyo3]
version = "0.24.1"
default-features = false
features = ["macros", "extension-module"]

[dependencies.cfg-if]
version = "1.0.0"

[dependencies.parking_lot_core]
version = "0.9.10"
default-features = false

[dependencies.lock_api]
version = "0.4.12"
default-features = false

[build-dependencies.pyo3-build-config]
version = "0.24.1"
features = ["resolve-config"]

[lints.clippy]
dbg_macro = "warn"
Expand Down
40 changes: 21 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
.DEFAULT_GOAL := all
export CARGO_TERM_COLOR=$(shell (test -t 0 && echo "always") || echo "auto")
help:
@echo "Commands:"
@echo -e "\tbuild-dev build source"
@echo -e "\tbuild-prod build source (release mode)"
@echo -e "\ttest-rs clippy and test rust code"
@echo -e "\ttest-py build and test python code"
@echo -e "\tformat format rust and python code"
@echo -e "\tclean clean all the unneeded files"

.PHONY: build-dev
build-dev:
maturin develop


.PHONY: build-prod
build-prod:
maturin develop --release


.PHONY: test-py
test-py:
maturin develop
RUST_BACKTRACE=1 pytest -vv
rm -rf .pytest_cache
ruff check .
ruff clean


.PHONY: test-rs
test-rs:
cargo clippy
cargo test -- --nocapture

.PHONY: test-py
test-py: build-dev
coverage run -m pytest -s -vv
-rm -rf .pytest_cache
-ruff check .
ruff clean
coverage html

.PHONY: format
format:
ruff format --line-length=100 .
ruff clean
cargo fmt


.PHONY: clean
clean:
-rm -rf `find . -name __pycache__`
-rm -rf cachebox/*.so
-rm -rf python/cachebox/*.so
-rm -rf target/release


.PHONY: all
all: format test-rs test-py clean
-rm -rf .pytest_cache
-rm -rf .coverage
-rm -rf htmlcov
-ruff clean
Loading