Skip to content

v1.2.3#24

Open
lxzan wants to merge 6 commits into
mainfrom
dev
Open

v1.2.3#24
lxzan wants to merge 6 commits into
mainfrom
dev

Conversation

@lxzan

@lxzan lxzan commented Jul 7, 2026

Copy link
Copy Markdown
Owner

No description provided.

lxzan and others added 6 commits January 5, 2024 11:40
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants