wickjon
wickjon

Reputation: 920

How to retreive memory cache in Azure app service

I am hosting a Net core application as as Azure app service. The app uses Microsoft.Extensions.Caching.Memoryto set and get string values to cache. Is there a way I can see the key-values stored in my server's in-memory cache ?

Reason:- The values I set, always seem to be null when I retrieve them. Is there anything like Redis console in azure portal to check the key values present in memory cache?

the part of code used to set and get.

_memoryCache.Set("key1", "value1", TimeSpan.FromHours(1))

_memoryCache.TryGetValue("key1", out string result)

Upvotes: 0

Views: 1418

Answers (1)

Jason Pan
Jason Pan

Reputation: 21838

There is no function you mentioned on the azure portal.

Follow below steps, you can retrieve the value.

You need add services.AddMemoryCache(); in ConfigureServices.

enter image description here

And you also change your controller like below. Then you will get the value. It will not be null.

enter image description here

Upvotes: 1

Related Questions