Skip to content

v6.0: Full Refactor#53

Merged
awolverp merged 62 commits into
mainfrom
v6
Jun 2, 2026
Merged

v6.0: Full Refactor#53
awolverp merged 62 commits into
mainfrom
v6

Conversation

@awolverp
Copy link
Copy Markdown
Owner

@awolverp awolverp commented Jun 1, 2026

This PR upgrades cachebox to version v6.0. The library has been completely optimized and rewritten for maximum performance and stability. All core algorithms have been reviewed and improved, multiple long-standing bugs have been fixed, and several requested features have been added.

New Features

  • Added postprocess parameter to the @cached decorator, providing much more flexible control over cached results (replaces the deprecated copy_level).
  • Added getsizeof parameter to cache classes. This callable allows implementing weighted caching based on memory footprint, object size, or any custom logic.
  • Background sweeping support for TTLCache and VTTLCache via the new sweep_interval parameter. When set, a background thread automatically cleans up expired items (Add grace time to TTLCache #46).
  • New methods added to all cache classes:
    • current_size()
    • remaining_size()
    • contains()
  • Added helper functions for better type hinting:
    • get_cached_cache()
    • get_cached_cache_info()
    • get_cached_callback()
    • clear_cached_cache()

Changes

  • The entire library is now implemented in Rust using PyO3. Python wrapper classes have been removed.
  • Significant performance improvements (very large speed gains).
  • Major algorithmic improvements to FIFOCache and TTLCache.
  • Tests has been expanded and improved for better coverage and reliability.
  • All docstrings have been expanded with explanations of algorithms.
  • Mimalloc allocator has been removed.
  • All dependencies has been updated.
  • @cached decorator now uses LRUCache by default, instead of FIFOCache.

Breaking Changes

  • copy_level parameter in @cached has been deprecated and no longer has any effect.
  • TTLCache.ttl has been renamed to TTLCache.global_ttl to avoid confusion with per-item TTL.
  • cachedmethod decorator has been completely removed (deprecated since v5.1.0).
  • maxmemory parameter has been removed due to severe performance regression. Use getsizeof for weighted caching instead.
  • Pickle states structure changed (__getstate__ / __setstate__). Pickled caches from v5 may not be compatible with v6.

Bug Fixes

awolverp added 30 commits May 17, 2026 18:25
My targets:
- Use the new version of dependencies and the new advantages of them
- Use the customized hashbrown's raw
- Remove the Python layer of cache implementations, due to PyO3 updates which allows us to have __init__ method.
- Use less unsafe codes ( I try to, actually )
- Use rust nightly features to optimize code
- Fix some bugs
- And make the base ready for async implementations
Separated variables which are thread-safe, or can be atomic, to prevent using locks for a long time,
and this helps us in async implementations.
- TTLCache refactored
- Some edge case bugs fixed
- Tests improved
`VTTLCache` class refactored ( some methods are missing yet ).
`TTLCache` and `LFUCache` has performance improvements.
awolverp added 18 commits May 30, 2026 12:22
- Replaced `copy_level` parameter with more flexible `postprocess`
  callable (defaults to `postprocess_copy_mutables`). Now supports None
  (no copy), shallow copy, deep copy, or custom post-processing.
- Removed deprecated `cachedmethod` decorator (use cached(...,
  cache=lambda self: self._cache) instead).
- `CacheInfo` namedtuple no longer includes the `memory` field.
- Default cache changed from `FIFOCache` to `LRUCache`.
- Fixed incorrect `is_method` handling.
- Improved per-key lock management: now uses a plain `dict` instead of
  `defaultdict`, and removes the lock when no waiters remain (better
  memory behavior under high contention).
- Improved key makers (`make_key`, `make_hash_key`, `make_typed_key`)
@awolverp awolverp self-assigned this Jun 1, 2026
@awolverp awolverp added Bug Something isn't working Feature New feature or request Refactor labels Jun 1, 2026
@awolverp awolverp marked this pull request as ready for review June 1, 2026 16:15
@awolverp awolverp linked an issue Jun 1, 2026 that may be closed by this pull request
@awolverp awolverp merged commit d5e1df9 into main Jun 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Feature New feature or request Refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v6: Use customized hashbrown raw

1 participant