Skip to content

Conversation

@paulyuk
Copy link

@paulyuk paulyuk commented Nov 14, 2023

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.

Paul Yuknewicz added 2 commits November 14, 2023 09:57
Signed-off-by: Paul Yuknewicz <[email protected]>
@paulyuk paulyuk changed the title Adds state management and caching to Weather sample Adds state management and caching to AspireWithDapr Weather sample Nov 14, 2023
// 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>() {
Copy link
Member

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");
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

MOAR Caching

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