RedisMemoryCache.NetCore 1.0.1

dotnet add package RedisMemoryCache.NetCore --version 1.0.1
NuGet\Install-Package RedisMemoryCache.NetCore -Version 1.0.1
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="RedisMemoryCache.NetCore" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RedisMemoryCache.NetCore --version 1.0.1
#r "nuget: RedisMemoryCache.NetCore, 1.0.1"
#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 RedisMemoryCache.NetCore as a Cake Addin
#addin nuget:?package=RedisMemoryCache.NetCore&version=1.0.1

// Install RedisMemoryCache.NetCore as a Cake Tool
#tool nuget:?package=RedisMemoryCache.NetCore&version=1.0.1

RedisMemoryCache.NetCore

License: MIT nuget

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. Depends on MemoryCache.NetCore and Depends on TimedMemoryCache.NetCore

Install

From a command prompt

dotnet add package RedisMemoryCache.NetCore
Install-Package RedisMemoryCache.NetCore

You can also search for package via your nuget ui / website:

https://www.nuget.org/packages/RedisMemoryCache.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, and the default "expires" set in the constructor.
var cache = new RedisMemoryCache(connectionString, 3, TimeSpan.FromSeconds(30))
{
  ["caw"] = "caw caw caw", 
  ["caw2"] = new KeyValuePair<string, string>("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"];

// You can set an entry directly. It will inherit the "default" timeout, and the default "expires" set in the constructor.
cache["caw3"] = "third caw!";

// You can still set non-serializable values in memory, however, they will NOT be stored in Redis, and will inherit the "default" timeout, and the default "expires" set in the constructor.
// You can override the timeout by setting it to 0 in which case it will remain in memory until .Dispose
cache.Write("caw4", new MemoryStream(new byte[] {32, 34}), 0);

// You can set the timeout, and expires directly using the Write method.
cache.Write("caw5", true, 10, TimeSpan.FromMinutes(2));


// When cache entries expire they will first be checked in redis, if they exist, they will be re-added with the same timeout they were set with.
// If they do not exist in redis they will be removed, finally if redis times out during a read, the previous value will be used but considered "stale"
cache.OnTimeout += (source, key, value, timeout, stale, removed) =>
{
  Console.WriteLine($"{key}: stale={stale} removed={removed}");
};

Constructor

Set's the default timeout for all writes that do not specify there own timeout. Can also set the timespan for redis writes that do not specify there own. Finally synchronize can be set to false if you do not want your write, and deletes to be synchronized with Redis by default.

RedisMemoryCache(string connectionString, int seconds = 300, TimeSpan? expires = null, bool synchronize = true)

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 dynamic value to cache with own timeout without returning anything and setting the redis value to expire when the TimeSpan is reached.

void Write(string key, dynamic value, long timeout, TimeSpan? expires)

Write a dynamic value to cache with own timeout without returning anything and setting the redis value to expire when the TimeSpan is reached. You can also specify synchronize as false if you wish to write the value to memory only.

void Write(string key, dynamic value, long timeout, TimeSpan? expires, bool synchronize)

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)

Write a T value to cache with own timeout returning the T value from cache and setting the redis value to expire when the TimeSpan is reached.

T Write<T>(string key, T value, long timeout, TimeSpan? expires)

Write a T value to cache with own timeout returning the T value from cache and setting the redis value to expire when the TimeSpan is reached. You can also specify synchronize as false if you wish to write the value to memory only.

T Write<T>(string key, T value, long timeout, TimeSpan? expires, bool synchronize)

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 without returning anything. You can also specify synchronize as false if you wish to delete the value from memory only.

void Delete(string key, bool synchronize)

Delete an entry from cache returning that value as T

T Delete<T>(string key)

Delete an entry from cache returning that value as T. You can also specify synchronize as false if you wish to delete the value from memory only.

T Delete<T>(string key, bool synchronize)
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 442 1/21/2021
1.0.0 449 8/21/2020