MemoryCache.Net
1.0.0
dotnet add package MemoryCache.Net --version 1.0.0
NuGet\Install-Package MemoryCache.Net -Version 1.0.0
<PackageReference Include="MemoryCache.Net" Version="1.0.0" />
paket add MemoryCache.Net --version 1.0.0
#r "nuget: MemoryCache.Net, 1.0.0"
// Install MemoryCache.Net as a Cake Addin #addin nuget:?package=MemoryCache.Net&version=1.0.0 // Install MemoryCache.Net as a Cake Tool #tool nuget:?package=MemoryCache.Net&version=1.0.0
MemoryCache.Net
Implementation of a parallel thread-safe in-memory caching system with save, and load support suited for 'state' programming.
Install
From a command prompt
dotnet add package MemoryCache.Net
Install-Package MemoryCache.Net
You can also search for package via your nuget ui / website:
https://www.nuget.org/packages/MemoryCache.Net/
Examples
You can find more examples in the github examples project.
// You can populate the cache at initialization time
using var cache = new MemoryCache
{
["caw"] = "caw caw caw"
};
// You can also access an entry directly by key. However you will need to cast from dynamic using this method.
var caw1 = (string)cache["caw"];
cache["caw"] = "caw caw caw 2";
// You can create new entries directly by key, and they can be complex types!
cache["object"] = new KeyValuePair<string, int>("test", 42);
// However, non-serializable complex types will be "ignored" during .Save
cache["stream"] = new MemoryStream(new byte[] { 32, 34 });
// You can also use the Read<T>, and Write<T> methods. These methods handle casting for you to and from dynamic.
var caw2 = cache.Read<string>("caw");
cache.Write("caw", "caw caw caw 3");
// You can save cache using either Binary, or Json serialization by specifying either byte[], or string as T during save.
var binary = cache.Save<byte[]>();
var json = cache.Save<string>();
// You can reload cache from another source such as disk, or socket. With the option of clearing any existing data.
cache.Load(binary);
Constructor
MemoryCache()
Methods
Write a dynamic value to cache without returning anything
void Write(string key, dynamic value)
Write a T value to cache returning the T value from cache
T Write<T>(string key, T value)
Read a value from cache returning as T
T Read<T>(string key)
Delete an entry from cache without returning anything
void Delete(string key)
Delete an entry from cache returning that value as T
T Delete<T>(string key)
Serialize all entries in cache marked as serializable. If you specify T as byte[] binary serialization is used. If you specify T as string json serialization is used.
T Save<T>()
Load serialized entries into cache. If you specify T as byte[] binary serialization is used. If you specify T as string json serialization is used.
void Load<T>(T data, bool clear = true)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.5
- Newtonsoft.Json (>= 12.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MemoryCache.Net:
Package | Downloads |
---|---|
TimedMemoryCache.Net
Implementation of a parallel thread-safe in-memory caching system with save, and load support suited for 'state' programming and easy timeout support for time sensitive caching. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 502 | 8/25/2020 |