-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds state management and caching to AspireWithDapr Weather sample #29
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Paul Yuknewicz <paulyuk@Pauls-MBP-2.lan>
Signed-off-by: Paul Yuknewicz <paulyuk@Pauls-MBP-2.lan>
// If it doesn't exist, get it from the weather service | ||
weatherData = await daprClient.InvokeMethodAsync<WeatherForecast[]>(HttpMethod.Get, apiAppId, "weatherforecast"); | ||
|
||
await daprClient.SaveStateAsync(stateStore, "weather", weatherData, metadata: new Dictionary<string, string>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the metadata
parameter typed as Dictionary<string, string>
? If so, we can simplify to use target-typed new
here. If not, oh well 😄
return await daprClient.InvokeMethodAsync<WeatherForecast[]>(HttpMethod.Get, "api", "weatherforecast"); | ||
|
||
// Get the weather from the state store if it exists | ||
var weatherData = await daprClient.GetStateAsync<WeatherForecast[]>(stateStore, "weather"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This app also uses output caching at the UI layer. Does it make sense to use both? Should we remove the output caching and use this instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point. Technically they're caching at different levels (API response vs. full HTML response) so could still be argued it's valuable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MOAR Caching
The current sample showcases service invoke + nice treatment of sidecars.
This shows just a bit more around using powerful APIs like state management along with built in integrations with Redis to achieve a better result, simply.