Skip to content

Commit a0ccb81

Browse files
committed
Fix #23 issue
1 parent 490f9df commit a0ccb81

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 4.5.3 - 2025-03-31
9+
### Changed
10+
- 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).
11+
12+
## 4.5.2 - 2025-03-14
13+
### Changed
14+
- In previous version, `clear_cache`, does not clear the exceptions dictionary. Thanks to @dada-engineer for the fix [#22](https://github.com/awolverp/cachebox/pull/22).
15+
16+
## 4.5.1 - 2025-02-01
17+
### Changed
18+
- In previous version, the `cached` and `cachedmethod` functions caught a `KeyError` from the callback function, which led to the cached function being called again. Thanks to @AlePiccin for the issue [#20](https://github.com/awolverp/cachebox/issues/20).
19+
820
## 4.5.0 - 2025-01-31
921
### Updated
1022
- `cached` and `cachedmethod` improved:

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cachebox"
3-
version = "4.5.2"
3+
version = "4.5.3"
44
edition = "2021"
55
description = "The fastest memoizing and caching Python library written in Rust"
66
readme = "README.md"

cachebox/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ def _wrapped(*args, **kwds):
261261

262262
with locks[key]:
263263
if exceptions.get(key, None) is not None:
264-
e = exceptions[key] if locks[key].waiters > 1 else exceptions.pop(key)
265-
raise e
264+
cached_error = exceptions[key] if locks[key].waiters > 1 else exceptions.pop(key)
265+
raise cached_error
266266

267267
try:
268268
result = cache[key]
@@ -272,7 +272,9 @@ def _wrapped(*args, **kwds):
272272
try:
273273
result = func(*args, **kwds)
274274
except Exception as e:
275-
exceptions[key] = e
275+
if locks[key].waiters > 1:
276+
exceptions[key] = e
277+
276278
raise e
277279

278280
else:
@@ -347,8 +349,8 @@ async def _wrapped(*args, **kwds):
347349

348350
async with locks[key]:
349351
if exceptions.get(key, None) is not None:
350-
e = exceptions[key] if locks[key].waiters > 1 else exceptions.pop(key)
351-
raise e
352+
cached_error = exceptions[key] if locks[key].waiters > 1 else exceptions.pop(key)
353+
raise cached_error
352354

353355
try:
354356
result = cache[key]
@@ -358,7 +360,9 @@ async def _wrapped(*args, **kwds):
358360
try:
359361
result = await func(*args, **kwds)
360362
except Exception as e:
361-
exceptions[key] = e
363+
if locks[key].waiters > 1:
364+
exceptions[key] = e
365+
362366
raise e
363367

364368
else:

0 commit comments

Comments
 (0)