Dynamically Compiled Expressions

Caching dynamically compiled expressions in RCommon

RCommon utilizes dynamically compiled expressions in many areas of CQRS implementations as well as persistence. The inherent overhead associated with reflection used in compiling those expressions is fairly substantial. While this is not an uncommon problem, it can be easily mitigated with caching.

Configuration

Note the use of "cache.CacheDynamicallyCompiledExpressions" statement below

var host = Host.CreateDefaultBuilder(args)
            .ConfigureServices(services =>
            {
                // Configure RCommon
                services.AddRCommon()
                    .WithJsonSerialization<JsonNetBuilder>() // Distributed memory caching requires serialization
                    .WithMemoryCaching<InMemoryCachingBuilder>(cache =>
                    {
                        cache.Configure(x =>
                        {
                            x.ExpirationScanFrequency = TimeSpan.FromMinutes(1);
                        });
                       
                    });
            }).Build();

Last updated