Drogecode.Blazor.ExpireStorage 1.0.0-rc1

This is a prerelease version of Drogecode.Blazor.ExpireStorage.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Drogecode.Blazor.ExpireStorage --version 1.0.0-rc1
                    
NuGet\Install-Package Drogecode.Blazor.ExpireStorage -Version 1.0.0-rc1
                    
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="Drogecode.Blazor.ExpireStorage" Version="1.0.0-rc1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Drogecode.Blazor.ExpireStorage" Version="1.0.0-rc1" />
                    
Directory.Packages.props
<PackageReference Include="Drogecode.Blazor.ExpireStorage" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Drogecode.Blazor.ExpireStorage --version 1.0.0-rc1
                    
#r "nuget: Drogecode.Blazor.ExpireStorage, 1.0.0-rc1"
                    
#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.
#:package Drogecode.Blazor.ExpireStorage@1.0.0-rc1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Drogecode.Blazor.ExpireStorage&version=1.0.0-rc1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Drogecode.Blazor.ExpireStorage&version=1.0.0-rc1&prerelease
                    
Install as a Cake Tool

Nuget version

Drogecode.Blazor.ExpireStorage

Store api responses in localstorage and sessionstorage.

Configure if the api should be called or the cached value will be returned if available.

Installing

To install the package, add the following line to the csproj file. Replacing x.x.x with the latest version number (found at the top of this file):

<PackageReference Include="Drogecode.Blazor.ExpireStorage" Version="x.x.x" />

You can also install via the .NET CLI with the following command:

dotnet add package Drogecode.Blazor.ExpireStorage

If you're using Visual Studio you can also install via the built in NuGet package manager.

Setup

You will need to register the expire storage services with the service collection in your Startup.cs file in Blazor Server.

public void ConfigureServices(IServiceCollection services)
{
    services.AddExpireStorage();
}

Or in your Program.cs file in Blazor WebAssembly.

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.RootComponents.Add<App>("app");

    builder.Services.AddExpireStorage();

    await builder.Build().RunAsync();
}

Usage (Blazor WebAssembly)

example

@inject Drogecode.Blazor.ExpireStorage.IExpireStorageService storageService

@code {
    
    public async Task<YourObjectResponse?> GetDayItemsAsync(DateRange dateRange, Guid userId, CancellationToken clt)
    {
        var cacheKey = "CACHE_KEY_HERE"
        var response = await storageService.CachedRequestAsync(cacheKey,
            async () => await apiClient.GetItemsAsync(),
            new CachedRequest{CachedAndReplace = true},
            new YourObjectResponse(),
            clt);
        return response;
    }

}

Options

CachedRequest

You can give optional settings to the CachedRequest object.

  • OneCallPerLocalStorage - If true, the result will be returned from localstorage if it is not expired. Default: false
  • OneCallPerSession - If true, the result will be returned from sessionstorage if it is not expired. Default: false
  • ExpireLocalStorage - The DateTime the localstorage value will be expired. Default: 7 days.
  • ExpireSessionStorage - The DateTime the sessionstorage value will be expired. Default: 15 minutes.
  • IgnoreCache - If true, never return a cached result. Default: false
  • CachedAndReplace - If true, The cached result will be returned and the cache will be refreshed for the next call. Default: false
  • CacheWhenOffline - If true, the cached result will be returned when offline, except when IgnoreCache is true. Default: false
  • RetryOnJsonException - If true, If a JSON exception occurs, the cache will be cleared and the request will be retried once. This will minimize the effect if a breaking change was introduced in the JSON value. Default: true

Global settings

Postfix

On, for example, MainLayout.razor.cs, you can set the Postfix to be used for all requests. This is useful if you have multiple users using the same app from the same browser.

ExpireStorageService.Postfix = userId.ToString();

IsOffline

ExpireStorageService knows two properties to monitor if the app is offline.

IsOffline is true when the last request had an HttpRequestException, after a successful request IsOffline will be false.

ExpireStorageService.IsOffline and ExpireStorageService.IsOfflineChanged

LogToConsole

ExpireStorageService can log to the console if you want to see what is happening, default: false.

ExpireStorageService.LogToConsole = true;

ICacheableResponse

If a response object implements ICacheableResponse, the HandledBy property will be set to HandledBy.Cache if the result was retrieved from cache and to HandledBy.Default if the default provided by the caller was used.

using Drogecode.Blazor.ExpireStorage;
public class YourObjectResponse : ICacheableResponse
{
    ...
    public HandledBy HandledBy { get; set; }
    ...
}

Cache

The cache is stored as a base64 string and serialized / deserialized using System.Text.Json.

Cleanup

One minute after the app starts, the local storage cache will be cleared from all expired values.

Items that are expired but not yet deleted will not be returned.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows 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.0.0 95 5/2/2026
1.0.0-rc4 110 4/26/2026
1.0.0-rc3 86 4/26/2026
1.0.0-rc2 97 4/26/2026
1.0.0-rc1 80 4/26/2026
0.2.7 151 4/15/2026
0.2.4 216 3/21/2026
0.2.2 96 3/19/2026
0.2.1 94 3/18/2026
0.1.2 410 12/28/2025
0.1.1 303 11/15/2025
0.1.0 249 11/3/2025
Loading failed