TimedMemoryCache.Net
1.0.0
dotnet add package TimedMemoryCache.Net --version 1.0.0
NuGet\Install-Package TimedMemoryCache.Net -Version 1.0.0
<PackageReference Include="TimedMemoryCache.Net" Version="1.0.0" />
paket add TimedMemoryCache.Net --version 1.0.0
#r "nuget: TimedMemoryCache.Net, 1.0.0"
// Install TimedMemoryCache.Net as a Cake Addin #addin nuget:?package=TimedMemoryCache.Net&version=1.0.0 // Install TimedMemoryCache.Net as a Cake Tool #tool nuget:?package=TimedMemoryCache.Net&version=1.0.0
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. Depends on MemoryCache.Net
Install
From a command prompt
dotnet add package TimedMemoryCache.Net
Install-Package TimedMemoryCache.Net
You can also search for package via your nuget ui / website:
https://www.nuget.org/packages/TimedMemoryCache.Net/
Examples
You can find more examples in the github examples project.
// You can populate the cache at initialization time, it will inherit the "default" timeout set in the constructor.
var cache = new TimedMemoryCache(10)
{
["caw"] = "first 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"];
// Will inherit the "default" timeout set in the constructor.
cache["caw2"] = "second caw!";
// You can also override the default timeout and set your own using the Write method!
cache.Write("caw3", "third caw!", 20);
// You can use the OnTimeout event to catch the key, and value of what is removed. You can re-add it back if you want using source, or a stored cache variable.
cache.OnTimeout += (source, key, value) =>
{
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Removed '{key}'");
};
Constructor
Timeout is in seconds. Set's the default timeout for all writes that do not specify there own timeout.
TimedMemoryCache(long timeout)
Methods
Write a dynamic value to cache with default timeout without returning anything
void Write(string key, dynamic value)
Write a dynamic value to cache with own timeout without returning anything
void Write(string key, dynamic value, long timeout)
Write a T value to cache with default timeout returning the T value from cache
T Write<T>(string key, T value)
Write a T value to cache with own timeout returning the T value from cache
T Write<T>(string key, T value, long timeout)
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
- MemoryCache.Net (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TimedMemoryCache.Net:
Package | Downloads |
---|---|
RedisMemoryCache.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 with Redis support. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 419 | 8/26/2020 |