OpenWeatherMap.Cache 1.12.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package OpenWeatherMap.Cache --version 1.12.1                
NuGet\Install-Package OpenWeatherMap.Cache -Version 1.12.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenWeatherMap.Cache" Version="1.12.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenWeatherMap.Cache --version 1.12.1                
#r "nuget: OpenWeatherMap.Cache, 1.12.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OpenWeatherMap.Cache as a Cake Addin
#addin nuget:?package=OpenWeatherMap.Cache&version=1.12.1

// Install OpenWeatherMap.Cache as a Cake Tool
#tool nuget:?package=OpenWeatherMap.Cache&version=1.12.1                

OpenWeatherMap.Cache OpenWeatherMap.Cache

GitHub Workflow Status NuGet NuGet Codacy Grade Codecov

An asynchronous .NET Standard 2.0 library that allows you to fetch & cache current weather readings from the OpenWeather API, with built-in resiliency that can extend the cache lifetime in case the API is unreachable.

Supports .NET Framework 4.6.1 or later, .NET Core 2.0 or later, and .NET 5.0 or later.

Installation

The recommended means is to use NuGet, but you could also download the source code from here.

Choose the fetch mode

If the time elapsed since the last fetch for the given location exceeds the cache period (i.e. a new API call is required) but is within the resiliency period (i.e. the previous readings are still available in the cache), the API reported measured time in the cache value is sometimes more recent than the latest value fetched from the API. There are three modes to tackle this issue:

With FetchMode.AlwaysUseLastMeasured, the value still available in the cache is returned. The implication is that if you immediately request another reading it will also hit the API again. IMPORTANT: Frequent calls may impact your API usage.

With FetchMode.AlwaysUseLastMeasuredButExtendCache (default, recommended), the value still available in the cache is returned but in order to protect impact on your API usage, this setting updates the cache value's fetched date and extends the cache lifetime.

With FetchMode.AlwaysUseLastFetchedValue, the last fetched API result is returned anyway, even though it is being reported to be older by the API.

Initialization with Dependency Injection

In your Startup.cs (ConfigureServices):

services.AddOpenWeatherMapCache("[API KEY]", 9_500, FetchMode.AlwaysUseLastMeasuredButExtendCache, 300_000);

Then you can inject IOpenWeatherMapCache.

Initialization without Dependency Injection

Create your own instance:

var openWeatherMapCache = new OpenWeatherMapCache("[API KEY]", 9_500, FetchMode.AlwaysUseLastMeasuredButExtendCache, 300_000);
var locationQuery = new OpenWeatherMap.Cache.Models.Location(47.6371, -122.1237);
var readings = await openWeatherMapCache.GetReadingsAsync(locationQuery);
if (readings.IsSuccessful)
{
    ...
}
else
{
    var apiErrorCode = readings.Exception?.ApiErrorCode;
    var apiErrorMessage = readings.Exception?.ApiErrorMessage;
}

or by zip code (post code) and country code:

var locationQuery = new OpenWeatherMap.Cache.Models.ZipCode("94040", "us");
var readings = await openWeatherMapCache.GetReadingsAsync(locationQuery);
if (readings.IsSuccessful)
{
    ...
}
else
{
    var apiErrorCode = readings.Exception?.ApiErrorCode;
    var apiErrorMessage = readings.Exception?.ApiErrorMessage;
}

Usage in synchronous methods

var locationQuery = new OpenWeatherMap.Cache.Models.Location(47.6371, -122.1237);
var readings = openWeatherMapCache.GetReadings(locationQuery);
if (readings.IsSuccessful)
{
    ...
}
else
{
    var apiErrorCode = readings.Exception?.ApiErrorCode;
    var apiErrorMessage = readings.Exception?.ApiErrorMessage;
}

or by zip code (post code) and country code:

var locationQuery = new OpenWeatherMap.Cache.Models.ZipCode("94040", "us");
var readings = openWeatherMapCache.GetReadings(locationQuery);
if (readings.IsSuccessful)
{
    ...
}
else
{
    var apiErrorCode = readings.Exception?.ApiErrorCode;
    var apiErrorMessage = readings.Exception?.ApiErrorMessage;
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.12.2 179 11/22/2024
1.12.1 724 11/11/2024
1.12.0 129 10/13/2024
1.11.1 95 10/5/2024
1.11.0 232 8/20/2024
1.10.6 441 7/21/2024
1.10.5 138 7/10/2024
1.10.3 2,908 1/23/2024
1.10.2 148 1/15/2024
1.10.1 511 1/1/2024
1.9.13 139 12/30/2023
1.9.12 174 12/6/2023
1.9.11 171 12/3/2023
1.9.10 121 12/2/2023
1.9.9 452 10/11/2023
1.9.8 1,018 4/10/2023
1.9.7 190 4/7/2023
1.9.6 1,892 3/25/2023
1.9.5 212 3/25/2023
1.9.4 324 2/25/2023
1.9.3 602 2/13/2023
1.9.2 271 2/3/2023
1.9.1 311 1/29/2023
1.9.0 286 1/27/2023
1.8.9 297 1/26/2023
1.8.8 336 1/2/2023
1.8.7 294 12/29/2022
1.8.6 431 12/18/2022
1.8.5 310 12/16/2022
1.8.3 309 12/13/2022
1.8.2 311 12/12/2022
1.8.1 309 12/12/2022
1.8.0 348 12/3/2022
1.7.5 327 11/28/2022
1.7.4 448 11/26/2022
1.7.3 334 11/19/2022
1.7.2 2,014 11/13/2022
1.6.1 967 10/26/2022
1.6.0 395 10/23/2022
1.5.12 617 10/18/2022
1.5.11 411 10/16/2022
1.5.10 468 9/17/2022
1.5.9 706 6/29/2022
1.5.8 435 6/29/2022
1.5.7 455 6/18/2022
1.5.6 436 6/9/2022
1.5.5 456 5/15/2022
1.5.4 1,660 4/15/2022
1.5.3 1,006 3/13/2022
1.5.2 436 3/13/2022
1.5.1 445 3/11/2022
1.5.0 476 2/26/2022
1.4.10 837 1/26/2022
1.4.9 566 12/11/2021
1.4.8 296 11/27/2021
1.4.7 310 11/23/2021
1.4.5 303 11/22/2021
1.4.4 731 11/21/2021
1.4.3 385 11/14/2021
1.4.2 327 11/10/2021
1.4.1 325 11/7/2021
1.4.0 381 10/20/2021
1.3.5 1,712 6/20/2021
1.3.4 418 6/20/2021
1.3.3 460 12/26/2020
1.3.2 431 12/6/2020
1.3.1 463 11/30/2020
1.3.0 430 11/28/2020
1.2.1 513 11/27/2020
1.2.0 437 11/24/2020
1.1.1 464 11/23/2020
1.1.0 418 11/23/2020
1.0.5 469 11/22/2020
1.0.4 407 11/22/2020
1.0.3 413 11/22/2020
1.0.2 408 11/22/2020
1.0.1 420 11/22/2020
1.0.0 439 11/22/2020

Dependency update and cleaning.