Skip to content

Implementation of UnloadStateAsync#1750

Merged
WhitWaldo merged 11 commits into
dapr:masterfrom
olitomlinson:unload-async
May 9, 2026
Merged

Implementation of UnloadStateAsync#1750
WhitWaldo merged 11 commits into
dapr:masterfrom
olitomlinson:unload-async

Conversation

@olitomlinson

Copy link
Copy Markdown
Contributor

Description

Adds an UnloadStateAsync() method to the Actor StateManager, so that state can be removed from the cache, without being removed from disk

Issue reference

#1728

Please reference the issue this PR will close: #[1728]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Implementation of UnloadStateAsyc (dapr#1728)

Signed-off-by: Oliver Tomlinson <oliverjamestomlinson@gmail.com>

@WhitWaldo WhitWaldo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

At first pass, this looks great - I'll keep an eye out for when you pull it out of draft.

@olitomlinson olitomlinson changed the title Implementation of UnloadStateAsyc Implementation of UnloadStateAsync Mar 28, 2026
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A task that represents the asynchronous unload operation.</returns>
/// <exception cref="InvalidOperationException">Thrown if the state is modified and not yet persisted, unless allowed by options.</exception>
Task UnloadStateAsync(string stateName, UnloadStateOptions options = null, CancellationToken cancellationToken = default);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider adding as a default interface method with a NotImplementedException / virtual behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why?

@WhitWaldo WhitWaldo Apr 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this scenario, adding a default interface method to throw NotSupportedException isn't a meaningful inclusion because we already provide the concrete type implementing this interface ourselves, and this will ship with same-day support.

Especially as this project doesn't support dependency injection, I would not expect that developers have implemented their own types on this interface, modified the library to use them instead, update the package and see this new method on the interface and call it in their applications just to see a TypeLoadException because they didn't implement the method themselves - I just don't think that's likely. I wouldn't have expected them to wrap every actor invocation in a try/catch block either, so this would just shift throwing a TypeLoadException to an NotSupportedException - not a meaningful change here.

Comment thread src/Dapr.Actors/Runtime/UnloadStateOptions.cs Outdated
@olitomlinson olitomlinson marked this pull request as ready for review May 7, 2026 18:10
@olitomlinson olitomlinson requested review from a team as code owners May 7, 2026 18:10
@WhitWaldo WhitWaldo added this to the v1.18 milestone May 7, 2026

@WhitWaldo WhitWaldo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One missing license header

Comment thread src/Dapr.Actors/Runtime/UnloadStateOptions.cs Outdated
Signed-off-by: Oliver Tomlinson <oliverjamestomlinson@gmail.com>

@WhitWaldo WhitWaldo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@WhitWaldo WhitWaldo merged commit 9394ded into dapr:master May 9, 2026
393 of 411 checks passed
@marcduiker

Copy link
Copy Markdown
Contributor

@holopin-bot @olitomlinson sdk-badge Thank you! Here's a digital badge as a small token of appreciation.

@holopin-bot

holopin-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

Congratulations @olitomlinson, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/cmqbf65r3000ajy044rs8no1o

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants