2

I am writing a .NET Core based WebAPI. I want to utilize a Distributed Memory Cache for my development environment by registering an IDistributedCache in Startup.ConfigureServices.

public void ConfigureServices(IServiceCollection services)
{
    if (_hostContext.IsDevelopment())
    {
        services.AddDistributedMemoryCache();
    }
    else
    {
        services.AddDistributedRedisCache(options =>
        {
          options.Configuration = "localhost";
          options.InstanceName = "SampleInstance";
        });
    }
}

However, I dont want the data caching to eat up most of my RAM. How can I limit the DistributedMemoryCache to use only 2GIG for example?

1 Answer 1

6

AddDistributedMemoryCache() has an overload that allows you to configure a MemoryDistributedCacheOptions. You can do:

services.AddDistributedMemoryCache(options =>
{
   options.SizeLimit = 2000 * 1024 * 1024; // 2000MB
});

It looks like the default is 200MB.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.