Rystem.RepositoryFramework.Cache 6.0.4

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

// Install Rystem.RepositoryFramework.Cache as a Cake Tool
#tool nuget:?package=Rystem.RepositoryFramework.Cache&version=6.0.4

What is Rystem?

Cache

Examples

You can add a repository (with default blob integration for instance) and after attack an in memory cache for all methods. The RefreshTime is a property that adds an Expiration date to the cached value, in the example below you can see that after 20 seconds the in memory cache requests again to the repository pattern a new value for each key. The Methods is a flag that allows to setup what operations have to be cached.

Query → query will be cached with this key

var keyAsString = $"{nameof(RepositoryMethods.Query)}_{typeof(T).Name}_{FactoryName}_{filter.ToKey()}";

Operation → operation will be cached with this key

var keyAsString = $"{nameof(RepositoryMethods.Operation)}_{operation.Name}_{typeof(T).Name}_{FactoryName}_{filter.ToKey()}";

Get → query will be cached with this key

var keyAsString = $"{nameof(RepositoryMethods.Get)}_{typeof(T).Name}_{FactoryName}_{key.AsString()}";

Exist → query will be cached with this key

var keyAsString = $"{nameof(RepositoryMethod.Exist)}_{typeof(T).Name}_{FactoryName}_{key.AsString()}";

Now you can understand the special behavior for commands. If you set Insert and/or Update and/or Delete, during any command if you allowed it for each command automatically the framework will update the cache value, with updated or inserted value or removing the deleted value. The code below allows everything

x.Methods = RepositoryMethod.All

In the example below you're setting up the following behavior: setting up a cache only for Get operation, and update the Get cache when exists a new Insert or an Update, or a removal when Delete operation were perfomed.

x.Methods = RepositoryMethod.Get | RepositoryMethod.Insert | RepositoryMethod.Update | RepositoryMethod.Delete

Setup in DI

services
    .AddRepository<Plant, int>(settings =>
    {
        settings
            .WithInMemory();
        settings
            .WithInMemoryCache(x =>
            {
                x.ExpiringTime = TimeSpan.FromSeconds(1);
                x.Methods = RepositoryMethods.All;
            });
    });

Usage

You always will find the same interface. For instance

IRepository<Plant, int> repository

or if you added a query pattern or command pattern

IQuery<Plant, int> query 
ICommand<Plant, int> command

Distributed Cache

Based on this link you may use the standard interface IDistributedCache instead of create a custom IDistributedCache<T, TKey, TState>. For instance you may choose between three libraries: Distributed SQL Server cache, Distributed Redis cache, Distributed NCache cache. You need to add the cache

builder.Services.AddStackExchangeRedisCache(options =>
 {
     options.Configuration = builder.Configuration.GetConnectionString("MyRedisConStr");
     options.InstanceName = "SampleInstance";
 });

then you add the IDistributedCache implementation to your repository patterns or CQRS.

.AddRepository<Country, CountryKey>(builder =>
{
    builder
        .WithInMemory(inMemoryBuilder =>
        {
            inMemoryBuilder
                .PopulateWithRandomData(NumberOfEntries, NumberOfEntries);
        });
    builder
        .WithDistributedCache(distributedCacheBuilder =>
        {
            distributedCacheBuilder.ExpiringTime = TimeSpan.FromSeconds(10);
        });
});

or a mix of them

.AddRepository<Country, CountryKey>(builder =>
{
    builder
        .WithInMemory(inMemoryBuilder =>
        {
            inMemoryBuilder
                .PopulateWithRandomData(NumberOfEntries, NumberOfEntries);
        });
    builder
        .WithInMemoryCache(inMemoryCacheBuilder =>
        {
            inMemoryCacheBuilder.ExpiringTime = TimeSpan.FromSeconds(10);
        })
        .WithDistributedCache(distributedCacheBuilder =>
        {
            distributedCacheBuilder.ExpiringTime = TimeSpan.FromSeconds(10);
        });
});

and as always you will use the standard interface that is automatically integrated in the repository flow.

IRepository<User, string> repository;

The same is valid for ICommand and IQuery.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Rystem.RepositoryFramework.Cache:

Package Downloads
Rystem.RepositoryFramework.Cache.Azure.Storage.Blob

Rystem.RepositoryFramework allows you to use correctly concepts like repository pattern, CQRS and DDD. You have interfaces for your domains, auto-generated api, auto-generated HttpClient to simplify connection "api to front-end", a functionality for auto-population in memory of your models, a functionality to simulate exceptions and waiting time from external sources to improve your implementation/business test and load test.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.4 114 4/3/2024
6.0.3 276 3/25/2024
6.0.2 153 3/11/2024
6.0.0 966 11/21/2023
6.0.0-rc.6 91 10/25/2023
6.0.0-rc.5 65 10/25/2023
6.0.0-rc.4 58 10/23/2023
6.0.0-rc.3 57 10/19/2023
6.0.0-rc.2 65 10/18/2023
6.0.0-rc.1 67 10/16/2023
5.0.20 486 9/25/2023
5.0.19 481 9/10/2023
5.0.18 457 9/6/2023
5.0.17 445 9/6/2023
5.0.16 522 9/5/2023
5.0.15 469 9/5/2023
5.0.14 460 9/5/2023
5.0.13 456 9/1/2023
5.0.12 430 8/31/2023
5.0.11 462 8/30/2023
5.0.10 486 8/29/2023
5.0.9 454 8/24/2023
5.0.8 479 8/24/2023
5.0.7 481 8/23/2023
5.0.6 515 8/21/2023
5.0.5 489 8/21/2023
5.0.4 521 8/16/2023
5.0.3 576 8/2/2023
5.0.2 540 8/2/2023
5.0.1 567 8/1/2023
5.0.0 568 7/31/2023
4.1.26 595 7/20/2023
4.1.25 561 7/16/2023
4.1.24 658 6/13/2023
4.1.23 585 6/13/2023
4.1.22 881 5/30/2023
4.1.21 576 5/20/2023
4.1.20 315,600 4/19/2023
4.1.19 95,527 3/20/2023
4.1.18 683 3/20/2023
4.1.17 662 3/16/2023
4.1.16 668 3/16/2023
4.1.15 662 3/15/2023
4.1.14 1,749 3/9/2023
4.1.13 685 3/7/2023
4.1.12 836 2/10/2023
4.1.11 715 1/26/2023
4.1.10 730 1/22/2023
4.1.9 700 1/20/2023
4.1.8 713 1/18/2023
4.1.7 705 1/18/2023
4.1.6 720 1/17/2023
4.1.1 750 1/4/2023
4.1.0 750 1/1/2023
3.1.5 730 12/21/2022
3.1.3 736 12/12/2022
3.1.2 721 12/7/2022
3.1.1 736 12/7/2022
3.1.0 790 12/2/2022
3.0.29 732 12/1/2022
3.0.28 755 12/1/2022
3.0.27 790 11/23/2022
3.0.25 855 11/23/2022
3.0.24 859 11/18/2022
3.0.23 849 11/18/2022
3.0.22 851 11/15/2022
3.0.21 842 11/14/2022
3.0.20 881 11/13/2022
3.0.19 987 11/2/2022
3.0.18 852 11/2/2022
3.0.17 904 10/29/2022
3.0.16 909 10/29/2022
3.0.15 894 10/29/2022
3.0.14 1,030 10/24/2022
3.0.13 918 10/24/2022
3.0.12 912 10/17/2022
3.0.11 951 10/10/2022
3.0.10 949 10/6/2022
3.0.9 942 10/6/2022
3.0.8 932 10/6/2022
3.0.7 876 10/6/2022
3.0.6 944 10/5/2022
3.0.5 822 10/5/2022
3.0.4 962 10/5/2022
3.0.3 934 10/3/2022
3.0.2 930 9/30/2022
3.0.1 935 9/30/2022
2.0.17 829 9/29/2022
2.0.16 961 9/27/2022
2.0.15 1,006 9/27/2022
2.0.14 1,001 9/26/2022
2.0.13 960 9/26/2022
2.0.12 960 9/26/2022
2.0.11 985 9/25/2022
2.0.10 1,031 9/25/2022
2.0.9 997 9/22/2022
2.0.8 953 9/22/2022
2.0.6 983 9/20/2022
2.0.5 1,112 9/20/2022
2.0.4 954 9/20/2022
2.0.2 974 9/20/2022
2.0.1 1,033 9/13/2022
2.0.0 949 8/19/2022
1.1.24 1,043 7/30/2022
1.1.23 1,016 7/29/2022
1.1.22 869 7/29/2022
1.1.21 980 7/29/2022
1.1.20 993 7/29/2022
1.1.19 998 7/27/2022
1.1.17 1,050 7/27/2022
1.1.16 971 7/26/2022
1.1.15 991 7/25/2022
1.1.14 990 7/25/2022
1.1.13 967 7/22/2022
1.1.12 1,012 7/19/2022
1.1.11 1,002 7/19/2022
1.1.10 961 7/19/2022
1.1.9 1,001 7/19/2022
1.1.8 1,024 7/18/2022
1.1.7 987 7/18/2022
1.1.6 990 7/18/2022
1.1.5 1,020 7/17/2022
1.1.4 879 7/17/2022
1.1.3 1,129 7/17/2022
1.1.2 992 7/17/2022
1.1.0 1,014 7/17/2022
1.0.2 973 7/15/2022
1.0.1 875 7/15/2022
1.0.0 1,015 7/8/2022
0.10.7 970 7/7/2022
0.10.2 1,003 7/2/2022
0.10.1 1,020 7/1/2022
0.10.0 904 7/1/2022
0.9.10 957 6/20/2022
0.9.9 975 6/11/2022
0.9.7 866 6/9/2022
0.9.6 892 6/9/2022