HybridRedisCache 1.0.7
See the version list below for details.
dotnet add package HybridRedisCache --version 1.0.7
NuGet\Install-Package HybridRedisCache -Version 1.0.7
<PackageReference Include="HybridRedisCache" Version="1.0.7" />
paket add HybridRedisCache --version 1.0.7
#r "nuget: HybridRedisCache, 1.0.7"
// Install HybridRedisCache as a Cake Addin #addin nuget:?package=HybridRedisCache&version=1.0.7 // Install HybridRedisCache as a Cake Tool #tool nuget:?package=HybridRedisCache&version=1.0.7
HybridRedisCache
HybridRedisCache
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.
Types of Cache
Basically, there are two types of caching .NET Core supports
- In-Memory Caching
- Distributed Caching
When we use In-Memory Cache then in that case data is stored in the application server memory and whenever we need then we fetch data from that and use it wherever we need it. And in Distributed Caching there are many third-party mechanisms like Redis and many others. But in this section, we look into the Redis Cache in detail and how it works in the .NET Core
Distributed Caching
Basically, in the distributed cachin,g data are stored and shared between multiple servers Also, it�s easy to improve scalability and performance of the application after managing the load between multiple servers when we use multi-tenant application Suppose, In the future, if one server is crashed and restarted then the application does not have any impact because multiple servers are as per our need if we want Redis is the most popular cache which is used by many companies nowadays to improve the performance and scalability of the application. So, we are going to discuss Redis and usage one by one.
Redis Cache
Redis is an Open Source (BSD Licensed) in-memory Data Structure store used as a database. Basically, it is used to store the frequently used and some static data inside the cache and use and reserve that as per user requirement. There are many data structures present in the Redis which we are able to use like List, Set, Hashing, Stream, and many more to store the data.
Redis vs. In-Memory caching in single instance benchmark
Installation
You can install the HybridRedisCache
package using NuGet:
PM> Install-Package HybridRedisCache
Usage
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()
{
DefaultLocalExpirationTime = TimeSpan.FromMinutes(1),
DefaultDistributedExpirationTime = TimeSpan.FromDays(1),
InstanceName = "SampleApp",
ThrowIfDistributedCacheError = true,
RedisCacheConnectString = "localhost:6379",
BusRetryCount = 10,
EnableLogging = true,
FlushLocalCacheOnBusReconnection = true,
};
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");
Features
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 Redis
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.
When 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:
- Support for multiple cache layers, including in-memory and Redis caching layers
- Automatic expiration of cached data based on time-to-live (TTL) or sliding expiration policies
- Support for fire-and-forget caching, which allows you to quickly set a value in the cache without waiting for a response
- Support for asynchronous caching operations, which allows you to perform cache operations asynchronously and improve the responsiveness of your application
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.
Installation of Redis Cache with docker
Step 1
Install docker on your OS.
Step 2
Open bash and type below commands:
$ docker pull redis:latest
$ docker run --name redis -p 6379:6379 -d redis:latest
Test is redis running:
$ docker exec -it redis redis-cli
$ ping
Contributing
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:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes and commit them.
- Push your changes to your fork.
- Submit a pull request.
License
HybridRedisCache
is licensed under the Apache License, Version 2.0. See the LICENSE file for more information.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- StackExchange.Redis (>= 2.6.104)
- System.Text.Json (>= 7.0.2)
-
.NETStandard 2.0
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- StackExchange.Redis (>= 2.6.104)
- System.Text.Json (>= 7.0.2)
-
.NETStandard 2.1
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- StackExchange.Redis (>= 2.6.104)
- System.Text.Json (>= 7.0.2)
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- StackExchange.Redis (>= 2.6.104)
- System.Text.Json (>= 7.0.2)
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 |
---|---|---|
3.0.2 | 32 | 11/9/2024 |
3.0.1 | 34 | 11/9/2024 |
3.0.0 | 32 | 11/9/2024 |
2.4.3 | 90 | 11/2/2024 |
2.4.2 | 79 | 10/31/2024 |
2.4.1 | 69 | 10/30/2024 |
2.4.0 | 67 | 10/30/2024 |
2.3.1 | 11,889 | 4/27/2024 |
2.2.4 | 1,668 | 1/15/2024 |
2.2.3 | 158 | 1/3/2024 |
2.2.2 | 128 | 1/3/2024 |
2.2.1 | 131 | 1/3/2024 |
2.2.0 | 134 | 1/3/2024 |
2.1.0 | 139 | 12/31/2023 |
2.0.2 | 150 | 12/18/2023 |
2.0.1 | 141 | 12/12/2023 |
2.0.0 | 134 | 12/9/2023 |
1.9.0 | 144 | 12/8/2023 |
1.8.0 | 116 | 12/6/2023 |
1.6.0 | 132 | 12/4/2023 |
1.5.0 | 167 | 10/31/2023 |
1.4.0 | 153 | 10/15/2023 |
1.3.1 | 124 | 10/8/2023 |
1.3.0 | 132 | 9/10/2023 |
1.2.4 | 227 | 5/7/2023 |
1.2.3 | 141 | 5/5/2023 |
1.2.2 | 135 | 5/5/2023 |
1.2.1 | 125 | 5/5/2023 |
1.2.0 | 131 | 5/5/2023 |
1.1.1 | 138 | 5/4/2023 |
1.1.0 | 156 | 5/3/2023 |
1.0.9 | 143 | 5/1/2023 |
1.0.8 | 159 | 5/1/2023 |
1.0.7 | 153 | 4/30/2023 |
1.0.6 | 148 | 4/29/2023 |
1.0.5 | 155 | 4/29/2023 |
1.0.4 | 155 | 4/28/2023 |
1.0.3 | 159 | 4/28/2023 |
1.0.2 | 175 | 4/17/2023 |
1.0.1 | 161 | 4/16/2023 |
1.0.0 | 164 | 4/16/2023 |
Improved performance