question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Caching requires IDistributedCache

See original GitHub issue

If I try to turn on caching in the configuration I get the following error message

Caching is enabled, but no IDistributedCache is found in the services collection

Here’s the configuration:

public void ConfigureServices(IServiceCollection services) {
    services.AddAuthentication(OAuth2IntrospectionDefaults.AuthenticationScheme)
        .AddOAuth2Introspection(options => {
            options.Authority = "https://myidentityserver";
            options.ClientId = "myapi";
            options.ClientSecret = "myapisecret";
            options.EnableCaching = true;
        });

    services.AddControllers();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();
    app.UseEndpoints(endpoints => {
        endpoints.MapControllers();
    });
}

I don’t have my own IDistributedCache, so shouldn’t there be some default implementation that IdentityModel uses if it doesn’t find one in the DI container?

IdentityModel.AspNetCore.OAuth2Introspection version 4.0.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
fanc-msocommented, Jan 10, 2020

Just for reference, to help anybody else out, as I stumbled upon the same:

In Asp.net Core 2.2 you probably called services.AddMvc() in Startup, which itself adds DistributedMemoryCache implicitely.

In Asp.net Core 3.x, if you call only services.AddControllers(), the cache is not added by default. You have to add it explicitely, like by calling services.AddDistributedMemoryCache().

Hope that helps

0reactions
github-actions[bot]commented, Feb 20, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Distributed caching in ASP.NET Core
A distributed cache is a cache shared by multiple app servers, typically maintained as an external service to the app servers that access...
Read more >
Working with a Distributed Cache — ASP.NET documentation
A distributed cache is shared by multiple app servers (see Caching Basics). The information in the cache is not stored in the memory...
Read more >
Working With ASP.NET 6 IDistributedCache Provider For ...
This is the interface required to access the distributed cache objects, which includes synchronous and asynchronous methods.
Read more >
Caching in ASP.NET Core 3.1 using (IDistributedCache ...
A distributed cache is shared by multiple app servers. The information in a distributed cache is not available to just individual servers and...
Read more >
Distributed Caching in ASP.NET Core with Redis
Today's objective is to leverage the IDistributedCache to do some distributed caching so that we can horizontally scale out our web app.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found