Skip to content

Add TTL support and batch operations#2

Open
rogeeff wants to merge 1 commit into
masterfrom
feature/ttl-and-batch-ops
Open

Add TTL support and batch operations#2
rogeeff wants to merge 1 commit into
masterfrom
feature/ttl-and-batch-ops

Conversation

@rogeeff
Copy link
Copy Markdown
Owner

@rogeeff rogeeff commented May 27, 2026

Summary

This PR adds time-to-live (TTL) support to the cache, allowing entries to expire automatically after a configurable duration. It also introduces batch operations for improved efficiency when working with multiple entries at once.

Changes

  • TTL expiration: Each entry can optionally have a TTL (in seconds). Expired entries are lazily evicted on access or explicitly via cleanupExpired().
  • find() method: Returns a direct reference to cached values, avoiding the copy overhead of get() for large value types.
  • batch_get() / batch_put(): Bulk operations that acquire the lock once for better performance than individual calls in a loop.
  • Internal refactor: Extracted get_internal() and put_internal() helpers to support lock management for batch operations.
  • Benchmark updates: Added TTL benchmarking scenario and averaged multi-run benchmarks to the Python benchmark script.

Testing

  • Added unit tests for find(), TTL, batch operations, and cleanup
  • Existing tests pass unchanged

- Add Entry struct with TTL metadata
- Add find() method for direct reference access
- Add batch_get() and batch_put() for bulk operations
- Add cleanupExpired() to purge stale entries
- Refactor get/put to use internal helpers for lock management
- Update tests and benchmark script with TTL scenarios
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.

1 participant