A simple in-memory and Redis hybrid caching solution for .NET applications. It provides a way to cache frequently accessed data in memory for fast access and automatically falls back to using Redis as a persistent cache when memory cache capacity is exceeded.
$ dotnet add package HybridRedisCacheHybridRedisCache is a simple in-memory and Redis hybrid caching solution for .NET applications.
It provides a way to cache frequently accessed data in memory for fast access and automatically falls back to using Redis as a persistent cache when memory cache capacity is exceeded.
You can install the HybridRedisCache package using NuGet:
PM> Install-Package HybridRedisCache
To use HybridCache, you can create an instance of the HybridCache class and then call its Set and Get methods to cache and retrieve data, respectively.
Here's an example:
using HybridRedisCache;
...
// Create a new instance of HybridCache with cache options
var options = new HybridCachingOptions()
{
DefaultExpirationTime = TimeSpan.FromSeconds(1),
InstanceName = "SampleApp",
ThrowIfDistributedCacheError = true,
RedisCacheConnectString = "localhost:6379"
};
var cache = new HybridCache(options);
// Cache a string value with key "mykey" for 1 minute
cache.Set("mykey", "myvalue", TimeSpan.FromMinutes(1));
// Retrieve the cached value with key "mykey"
var value = cache.Get<string>("mykey");
HybridCache is a caching library that provides a number of advantages over traditional in-memory caching solutions.
One of its key features is the ability to persist caches between instances and sync data for all instances.
With HybridCache, you can create multiple instances of the cache that share the same cache,
allowing you to scale out your application and distribute caching across multiple instances.
This ensures that all instances of your application have access to the same cached data,
regardless of which instance originally created the cache.
RedisWhen a value is set in the cache using one instance, the cache invalidation message is sent to all other instances, ensuring that the cached data is synchronized across all instances. This allows you to take advantage of the benefits of caching, such as reduced latency and improved performance, while ensuring that the cached data is consistent across all instances.
Other features of HybridCache include:
Overall, HybridCache provides a powerful and flexible caching solution that can help you improve the performance and scalability of your applications, while ensuring that the cached data is consistent across all instances.
Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.
If you'd like to contribute to HybridRedisCache, please follow these steps:
HybridRedisCache is licensed under the Apache License, Version 2.0. See the LICENSE file for more information.