DiskMemCache 2.0.0
See the version list below for details.
dotnet add package DiskMemCache --version 2.0.0
NuGet\Install-Package DiskMemCache -Version 2.0.0
<PackageReference Include="DiskMemCache" Version="2.0.0" />
paket add DiskMemCache --version 2.0.0
#r "nuget: DiskMemCache, 2.0.0"
// Install DiskMemCache as a Cake Addin #addin nuget:?package=DiskMemCache&version=2.0.0 // Install DiskMemCache as a Cake Tool #tool nuget:?package=DiskMemCache&version=2.0.0
DiskMemCache
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));
Cache invalidation
You can invalidate cache either manually by calling
// Removes all cached entries stored in memory/files on disk
DiskMemCache.PurgeAll();
// 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));
Note
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 | Versions 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. |
-
.NETStandard 2.1
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Async only API.