feat: comprehensive refactoring and feature enhancements#23
Merged
Conversation
Major Changes: - Refactor MemoryCache architecture: remove bucketWrapper abstraction and inline bucket access logic for improved performance - Replace global callback with per-element callback support, enabling fine-grained event handling - Add bucketMask field for faster bucket indexing via bitmask operation New Features: - Add ReasonCleared callback reason for Clear() operation to notify alive non-expired elements - Add GetTTL() method to retrieve key expiration time without modifying it - Add GetWithTTL() method to get value and refresh expiration time atomically - Add UpdateTTL() method to update key expiration without retrieving value - Add Len() method for quick element count (includes uncleaned expired elements) - Add adaptive TTL check interval: dynamically adjusts cleanup frequency based on deletion volume Performance Optimizations: - Optimize heap operations with inline lessByIndex() and swapDirect() methods - Convert recursive heap Up/Down to iterative implementation, reducing call stack overhead - Add safety checks to heap Front() to prevent out-of-bounds access - Use time.Now() caching via atomic timestamp (CachedTime option) to reduce syscall overhead - Pre-compute bucketMask during initialization for O(1) bucket lookup Bug Fixes & Reliability: - Fix Stop() goroutine synchronization: move wg.Add(2) before goroutine spawn to prevent race conditions - Validate MinInterval/MaxInterval ordering in options initialization - Fix Fnv hash functions to iterate bytes instead of runes for correct string hashing - Add mc.Stop() defer in benchmark tests to prevent resource leaks Documentation: - Update README with comprehensive API documentation, options table, and improved examples - Add Clear() and Range() callback deadlock warnings in Chinese/English - Improve method descriptions with explicit behavior specifications Code Quality: - Remove deprecated bucketWrapper abstraction layer - Remove _ from range statements (Go idiomatic cleanup) - Remove unnecessary algo.Min dependency in heap - Clean up .editorconfig and .golangci.yaml configuration files - Update Map interface parameter naming for clarity Config Changes: - Add CachedTime option (default: true) for timestamp caching - Add MinInterval/MaxInterval for adaptive cleanup tuning - Remove global callback field from MemoryCache struct
Owner
|
mark |
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.
Major Changes:
New Features:
Performance Optimizations:
Bug Fixes & Reliability:
Documentation:
Code Quality:
Config Changes: