This is a simple example of how to use FusionCache in a .NET Core application to provide L1 and L2 caching.
It showcases selective cache invalidation using Tags.
We'll use this until Microsoft releases the official version of the HybridCache.
Microsoft.Extensions.Caching.HybridCache is currently in preview only, so may change.
docker-compose up -dto startredison port 6379dotnet runto start the application- Try the http examples in
Examples.http(or use Swagger UI)
-
Fusioncacheallows you to use multiple cache providers, but in this example, we are using onlyMemoryCacheandRedisCache. -
You can do tag based invalidation with
FusionCacheso you can invalidate ALL cache entries with that tag in one foul swoop. -
The tag is a string, so you can use it to group cache entries together.
-
Invalidation via tags does not actually remove the cache entries from the cache, it just marks them as invalid.
-
Sign up to OpenWeatherMap and get your API key to use the weather API. Update in
appsettings.json.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"OpenWeather": {
"ApiKey": "your-api-key-here"
}
}
- Added
FusionCacheto the project. - Added Configuration Options for
RedisandOpenWeatherApi - Added resiliency to the OpenWeather API calls using decorator pattern