DR.Cache
1.0.0
dotnet add package DR.Cache --version 1.0.0
NuGet\Install-Package DR.Cache -Version 1.0.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="DR.Cache" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DR.Cache --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DR.Cache, 1.0.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 DR.Cache as a Cake Addin #addin nuget:?package=DR.Cache&version=1.0.0 // Install DR.Cache as a Cake Tool #tool nuget:?package=DR.Cache&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DR.Cache
A small wrapper for Microsoft.Extensions.Caching.Memory
Usage
Here is an example on how you can use the library
using DR.Cache;
using Microsoft.Extensions.Caching.Memory;
namespace SomeProjct
{
public class Program
{
public partial class Data
{
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public List<string> Tags { get; set; } = new();
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
public double Price { get; set; }
}
static void Main(string[] args)
{
// Example data
string keyName = "woodenDoor";
Data productData = new Data()
{
Name = "Wooden door",
Description = "Height: 1.2m. Width: 40cm. Depth: 5cm.",
Tags = new() { "Door" , "Wood" },
Created = DateTime.ParseExact("24/05/2019", "d/M/yyyy", CultureInfo.InvariantCulture),
Updated = DateTime.ParseExact("04/08/2021", "d/M/yyyy", CultureInfo.InvariantCulture),
Price = 45.64
};
double updatedPrice = 38.30;
// Cache options
MemoryCacheOptions options = new()
{
// The maximum amount of items in cache.
SizeLimit = 100
};
// Global time for when cached items expire/get removed from cache
TimeSpan cacheExperationTime = TimeSpan.FromSeconds(10);
// Configure cache
_ = new Configuration(cacheExperationTime, options);
// Add item to cache
Cache.Set(keyName, productData);
// Check if item exists in cache
if (Cache.Exists(keyName))
{
// Get item from cache
productData = Cache.Get<Data>(keyName);
// Update cached item
productData.Price = updatedPrice;
Cache.Update(keyName, productData);
// Remove item from cache
Cache.Remove(keyName);
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release