DiskMemCache 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DiskMemCache --version 2.1.0
NuGet\Install-Package DiskMemCache -Version 2.1.0
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="DiskMemCache" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DiskMemCache --version 2.1.0
#r "nuget: DiskMemCache, 2.1.0"
#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 DiskMemCache as a Cake Addin
#addin nuget:?package=DiskMemCache&version=2.1.0

// Install DiskMemCache as a Cake Tool
#tool nuget:?package=DiskMemCache&version=2.1.0


Minimalistic persistence and caching library. Nuget available here.

Which problem it solves ?

Library was designed to solve issue of not wasting time while developing and application that needs to do some heavy or long computation of some data and you do not want to wait for that result every time you are developing an app, but you need the data to be there.

How it works ?

Every time you want to cache/persist result of operation you can wrap this call with:

// First call with this key will call provided function and also saves the result in:
// memory cache and also on filesystem as JSON
var result = await DiskMemCache.GetOrComputeAsync("exampleKey123", () => Task.FromResult(10));

// Next calls for operation with same key will be returned from memory cache
// or will be deserialized from file if application was restarted later on
var result = await DiskMemCache.GetOrComputeAsync("exampleKey123", () => Task.FromResult(10));

See tests for more examples.

Cache invalidation

You can invalidate cache either manually by calling

// Removes all cached entries stored in memory/files on disk

// Removes only operation with concrete key
DiskMemCache.Purge(key => key == "123");

or by using overload where you invalidate cache and "force" operation to be evaluated based on last caching time

// Force cache invalidation if cached entry existed more than your conditional logic
var x = await DiskMemCache.GetOrComputeAsync(key, () => Task.FromResult(10), t =>
// in this case 5 minutes ago
 t > TimeSpan.FromMinutes(5));


I do not want this library to be super extendable or configurable. If you are looking for something more complex and configurable look for more mature libraries.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
2.2.0 126 2/19/2024
2.1.0 87 2/18/2024
2.0.0 89 2/18/2024
1.0.0 85 2/18/2024

Namespace update.