Skip to content

IDX-7034 Add Cache::try_insert and Cache::try_find#43

Open
dalloriam wants to merge 3 commits into
feature/IDX-7025-api-improvementsfrom
feature/IDX-7025-try-insert
Open

IDX-7034 Add Cache::try_insert and Cache::try_find#43
dalloriam wants to merge 3 commits into
feature/IDX-7025-api-improvementsfrom
feature/IDX-7025-try-insert

Conversation

@dalloriam

@dalloriam dalloriam commented May 21, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Add non-blocking try_insert and try_find methods
  • Replace ThreadSafe bool template param by a LockingStrategy enum
  • Add TimedMutex to the LockingStrategy enum
  • Enable passing a timeout to try_insert and try_find if locking strategy is TimedMutex

Copilot AI left a comment

Copy link
Copy Markdown

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 introduces non-blocking and timed “try” cache operations (try_find / try_insert) and replaces the prior boolean thread-safety toggle with a more explicit LockingStrategy (None / Mutex / TimedMutex) to control locking behavior.

Changes:

  • Add LockingStrategy and mutex-selection utilities, and plumb this through Cache and preset aliases.
  • Add Cache::try_find / Cache::try_insert (immediate and timed variants) plus new tests covering contention/timeout behavior.
  • Update performance benchmarks and a single-thread swap test to use the new locking strategy template parameter.

Reviewed changes

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

Show a summary per file
File Description
tests/src/cache_tests.cpp Adds compile-time checks and runtime tests for try_find/try_insert, including contention and timed-lock scenarios.
include/cachemere/presets.h Replaces bool ThreadSafe with LockingStrategy in preset aliases and updates docs accordingly.
include/cachemere/detail/locking.h Introduces LockingStrategy, NullMutex, and mutex-type mapping utilities.
include/cachemere/cache.h Reworks cache locking to use LockingStrategy and implements try_find/try_insert APIs.
benchmarks/performance/src/bench_cache.cpp Updates benchmarks to instantiate caches with LockingStrategy::{Mutex,None} and fixes complexity type.

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

Comment thread include/cachemere/detail/locking.h
Comment thread tests/src/cache_tests.cpp
@dalloriam dalloriam changed the title draft: try_insert IDX-7034 Add Cache::try_insert and Cache::try_find May 21, 2026
@dalloriam
dalloriam marked this pull request as ready for review May 21, 2026 17:56
@dalloriam
dalloriam force-pushed the feature/IDX-7025-api-improvements branch from 93dfa25 to b3f9034 Compare May 27, 2026 12:50
@dalloriam
dalloriam force-pushed the feature/IDX-7025-try-insert branch from 067f16f to 8cf4125 Compare May 27, 2026 12:51
@dalloriam
dalloriam requested a review from bourque-julien May 28, 2026 15:11
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