TimedMemoryCache.NetCore
1.0.2
dotnet add package TimedMemoryCache.NetCore --version 1.0.2
NuGet\Install-Package TimedMemoryCache.NetCore -Version 1.0.2
<PackageReference Include="TimedMemoryCache.NetCore" Version="1.0.2" />
paket add TimedMemoryCache.NetCore --version 1.0.2
#r "nuget: TimedMemoryCache.NetCore, 1.0.2"
// Install TimedMemoryCache.NetCore as a Cake Addin #addin nuget:?package=TimedMemoryCache.NetCore&version=1.0.2 // Install TimedMemoryCache.NetCore as a Cake Tool #tool nuget:?package=TimedMemoryCache.NetCore&version=1.0.2
TimedMemoryCache.NetCore
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.NetCore
Install
From a command prompt
dotnet add package TimedMemoryCache.NetCore
Install-Package TimedMemoryCache.NetCore
You can also search for package via your nuget ui / website:
https://www.nuget.org/packages/TimedMemoryCache.NetCore/
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 | 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.1 is compatible. |
-
.NETCoreApp 3.1
- MemoryCache.NetCore (>= 1.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TimedMemoryCache.NetCore:
Package | Downloads |
---|---|
RedisMemoryCache.NetCore
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.