Skip to content

Conversation

@C-Pro
Copy link
Owner

@C-Pro C-Pro commented Jan 4, 2026

Add func (c *MapTTLCache[K, V]) OnEvict(f onEvictFunc[K, V]) function to set a callback on MapTTLCache to be called on each record evicted from the cache due to TTL expiration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an onEvict callback feature to MapTTLCache that allows users to be notified when cache entries are evicted due to TTL expiration. The callback is intentionally not called for explicit Del operations, only for automatic TTL-based evictions.

Key changes:

  • Added OnEvict method to set an eviction callback function
  • Integrated callback invocation into the cleanup process
  • Comprehensive test coverage for various eviction scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
map_ttl.go Adds onEvictFunc type, onEvict field to MapTTLCache, OnEvict setter method, and callback invocation in the cleanup method
ttl_test.go Adds three comprehensive tests: basic eviction callback, verification that Del doesn't trigger callback, and partial cleanup with batched evictions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@C-Pro C-Pro requested a review from arthhhhh23 January 9, 2026 14:43
@C-Pro C-Pro merged commit e3af37f into main Jan 10, 2026
5 checks passed
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