OpenWeatherMap.Cache 1.3.5

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

Install-Package OpenWeatherMap.Cache -Version 1.3.5
dotnet add package OpenWeatherMap.Cache --version 1.3.5
<PackageReference Include="OpenWeatherMap.Cache" Version="1.3.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenWeatherMap.Cache --version 1.3.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenWeatherMap.Cache, 1.3.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.3.5

// Install OpenWeatherMap.Cache as a Cake Tool
#tool nuget:?package=OpenWeatherMap.Cache&version=1.3.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

OpenWeatherMap.Cache

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

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 but is within the resiliency period (i.e. 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.

With FetchMode.AlwaysUseLastMeasured, the value still available in the cache is returned. IMPORTANT: Frequent calls may impact your API usage.

With FetchMode.AlwaysUseLastMeasuredButExtendCache (default), 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]", FetchMode.AlwaysUseLastMeasuredButExtendCache, 9_500, 300_000);

Then you can inject IOpenWeatherMapCache.

Initialization without Dependency Injection

Create your own instance:

var openWeatherMapCache = new OpenWeatherMapCache("[API KEY]", FetchMode.AlwaysUseLastMeasuredButExtendCache, 9_500, 300_000);

Usage in asynchronous methods (recommended)

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

Usage in synchronous methods

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

OpenWeatherMap.Cache

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

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 but is within the resiliency period (i.e. 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.

With FetchMode.AlwaysUseLastMeasured, the value still available in the cache is returned. IMPORTANT: Frequent calls may impact your API usage.

With FetchMode.AlwaysUseLastMeasuredButExtendCache (default), 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]", FetchMode.AlwaysUseLastMeasuredButExtendCache, 9_500, 300_000);

Then you can inject IOpenWeatherMapCache.

Initialization without Dependency Injection

Create your own instance:

var openWeatherMapCache = new OpenWeatherMapCache("[API KEY]", FetchMode.AlwaysUseLastMeasuredButExtendCache, 9_500, 300_000);

Usage in asynchronous methods (recommended)

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

Usage in synchronous methods

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

Release Notes

Added the possibility to log the results to file.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.5 95 6/20/2021
1.3.4 99 6/20/2021
1.3.3 154 12/26/2020
1.3.2 108 12/6/2020
1.3.1 146 11/30/2020
1.3.0 123 11/28/2020
1.2.1 169 11/27/2020
1.2.0 116 11/24/2020
1.1.1 145 11/23/2020
1.1.0 119 11/23/2020
1.0.5 167 11/22/2020
1.0.4 110 11/22/2020
1.0.3 119 11/22/2020
1.0.2 112 11/22/2020
1.0.1 121 11/22/2020
1.0.0 135 11/22/2020