Conversation
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.
- 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`)
…e_SetItem instead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
postprocessparameter to the@cacheddecorator, providing much more flexible control over cached results (replaces the deprecatedcopy_level).getsizeofparameter to cache classes. This callable allows implementing weighted caching based on memory footprint, object size, or any custom logic.TTLCacheandVTTLCachevia the newsweep_intervalparameter. When set, a background thread automatically cleans up expired items (Add grace time to TTLCache #46).current_size()remaining_size()contains()get_cached_cache()get_cached_cache_info()get_cached_callback()clear_cached_cache()Changes
FIFOCacheandTTLCache.@cacheddecorator now usesLRUCacheby default, instead ofFIFOCache.Breaking Changes
copy_levelparameter in@cachedhas been deprecated and no longer has any effect.TTLCache.ttlhas been renamed toTTLCache.global_ttlto avoid confusion with per-item TTL.cachedmethoddecorator has been completely removed (deprecated since v5.1.0).maxmemoryparameter has been removed due to severe performance regression. Usegetsizeoffor weighted caching instead.__getstate__/__setstate__). Pickled caches from v5 may not be compatible with v6.Bug Fixes