https://github.com/chrishoy/hybridcache-example
OpenWeatherMap API example using FusionCache to provide a hybrid cache using Redis
https://github.com/chrishoy/hybridcache-example
dotnet-core fusioncache openweathermap-api redis
Last synced: about 2 months ago
JSON representation
OpenWeatherMap API example using FusionCache to provide a hybrid cache using Redis
- Host: GitHub
- URL: https://github.com/chrishoy/hybridcache-example
- Owner: chrishoy
- License: mit
- Created: 2025-03-19T18:23:46.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-08T10:21:46.000Z (about 1 year ago)
- Last Synced: 2025-04-08T11:24:41.646Z (about 1 year ago)
- Topics: dotnet-core, fusioncache, openweathermap-api, redis
- Language: C#
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
- License: LICENSE.md
Awesome Lists containing this project
README
## OpenWeather API Example usage using FusionCache and Redis
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.
### How to use
- `docker-compose up -d` to start `redis` on port 6379
- `dotnet run` to start the application
- Try the http examples in `Examples.http` (or use Swagger UI)
### Note
- `Fusioncache` allows you to use multiple cache providers, but in this example, we are using only `MemoryCache` and `RedisCache`.
- You can do tag based invalidation with `FusionCache` so 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"
}
}
```
### Changes
- Added `FusionCache` to the project.
- Added Configuration Options for `Redis` and `OpenWeatherApi`
- Added resiliency to the OpenWeather API calls using decorator pattern