Occasionally there is the need to cache data that is coming from your persistence layer so that you can avoid hitting your data store repeatedly for data that is commonly used. RCommon provides a proxy for all repository implementations available in RCommon which allows you to use the repository pattern in conjunction with caching services.
Configuration
Note the usage of "ef.AddInMemoryPersistenceCaching" in the configuration below. This will configure the caching repository interfaces for you to use.
var host =Host.CreateDefaultBuilder(args) .ConfigureServices(services => { // Configure RCommonservices.AddRCommon() .WithPersistence<EFCorePerisistenceBuilder>(ef =>// Repository/ORM configuration. We could easily swap out to Linq2Db without impact to domain service up through the stack { // Add all the DbContexts hereef.AddDbContext<TestDbContext>("TestDbContext", ef => {ef.UseSqlServer(config.GetConnectionString("TestDbContext")); });ef.AddInMemoryPersistenceCaching(); // This gives us access to the caching repository interfaces/implementations }) // You still need to configure this as well! .WithMemoryCaching<InMemoryCachingBuilder>(cache => {cache.Configure(x => {x.ExpirationScanFrequency=TimeSpan.FromMinutes(1); }); }); }).Build();
It is still important that you configure caching in addition to adding persistence caching since that is what implements the caching abstractions.