Skip to content

Conversation

@caleblloyd
Copy link
Collaborator

Expose the ttl-versions of update

@caleblloyd caleblloyd requested a review from mtmk May 11, 2025 05:50
@mtmk
Copy link
Member

mtmk commented May 24, 2025

sorry for the delay on this one @caleblloyd. i'm guessing it's for extending the ttl i.e. sliding expirations? I'm not sure if this works as expected.

btw is this same subject would you say? #831 (comment)

@caleblloyd
Copy link
Collaborator Author

Yes, for sliding window updates. I think it is working fine here, had to cast to the concrete implementation though:

https://github.com/code-cargo/NatsDistributedCache/blob/4a4e7ed84e22df9e969597ee6df226333d9f5e4d/src/NatsDistributedCache/NatsCache.cs#L349

@mtmk
Copy link
Member

mtmk commented May 25, 2025

ah ok. so just to double check, is it doing what it's supposed to do? cause my understanding is that sliding expiration wasn't supported by the server

@caleblloyd
Copy link
Collaborator Author

caleblloyd commented May 27, 2025

True, I don't think sliding expiration is technically supported by the server. But it can be achieved by doing a Get, followed by an Update with Optimistic Concurrency Control on the revision that was retrieved, sending the exact same value back with a new TTL.

This PR is exposing the UpdateAsync (already exists in implementation) and TryUpdateAsync (added to the implementation) methods with TTL Paramaters in the INatsKvStore interface

They would be useful for anyone using the interface who wants to do an update with Optimistic Concurrency Control and a TTL, not just for sliding expiration.

It's more of an interface parity change than anything new... For example the TTL versions of CreateAsync and TryCreateAsync are already in the interface. While we are on the subject though, I noticed that there are not TTL versions of the PutAsync and TryPutAsync methods on the interface... Shall I add those to this PR as well?

@mtmk
Copy link
Member

mtmk commented May 28, 2025

There is a suggestion against put here https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-48.md#storing-values

Copy link
Member

@mtmk mtmk left a comment

Choose a reason for hiding this comment

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

LGTM

@mtmk mtmk merged commit c78d24d into main Jul 18, 2025
21 checks passed
@mtmk mtmk deleted the kv-interface-ttl branch July 18, 2025 09:15
mtmk added a commit that referenced this pull request Jul 18, 2025
* Fix kv wrong last sequence exception (#895)
* add ttl Update/TryUpdate to INatsKvStore (#852)
* [UPDATED] Add NATS Options Pattern DI Support (#888)
@mtmk mtmk mentioned this pull request Jul 18, 2025
mtmk added a commit that referenced this pull request Jul 21, 2025
* Fix kv wrong last sequence exception (#895)
* add ttl Update/TryUpdate to INatsKvStore (#852)
* [UPDATED] Add NATS Options Pattern DI Support (#888)
@mtmk mtmk mentioned this pull request Sep 22, 2025
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.

3 participants