Does the Cache Get Deleted If the Server Goes Into an Idle State?

%3CLINGO-SUB%20id%3D%22lingo-sub-2985021%22%20slang%3D%22en-US%22%3EDoes%20the%20Cache%20Get%20Deleted%20If%20the%20Server%20Goes%20Into%20an%20Idle%20State%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2985021%22%20slang%3D%22en-US%22%3E%3CP%3EOur%20application%20stores%20data%20in%20the%20server's%20memory%20using%20the%20IMemoryCache%20interface%20and%20is%20set%20to%20expire%20after%2055%20minutes.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Eprivate%20async%20Task%3CSTRING%3E%20GetTokenFromCacheAsync()%0A%7B%0A%20%20%20%20return%20await%20_cache.GetOrCreateAsync(%22accessToken%22%2C%20async%20entry%20%3D%26gt%3B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20entry.AbsoluteExpirationRelativeToNow%20%3D%20TimeSpan.FromSeconds(3300)%3B%0A%0A%20%20%20%20%20%20%20%20return%20await%20GetAccessTokenAsync()%3B%0A%20%20%20%20%7D)%3B%0A%7D%3C%2FSTRING%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20we%20noticed%20is%20that%20whenever%20the%20IIS%20server%20goes%20into%20an%20idle%20state%20(as%20set%20by%20the%20idle%20timeout%20property)%2C%20the%20cache%20gets%20deleted.%20Is%20there%20a%20way%20to%20mitigate%20this%20problem%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2985021%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWeb%20API%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

Our application stores data in the server's memory using the IMemoryCache interface and is set to expire after 55 minutes. 

 

 

private async Task<string> GetTokenFromCacheAsync()
{
    return await _cache.GetOrCreateAsync("accessToken", async entry =>
    {
        entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3300);

        return await GetAccessTokenAsync();
    });
}

 

 

What we noticed is that whenever the IIS server goes into an idle state (as set by the idle timeout property), the cache gets deleted. Is there a way to mitigate this problem?

0 Replies