How to get cache Expire Time

Bhuwan 881 Reputation points
2022-09-19T07:06:31.277+00:00

Hi

How to get cache expiration Exact Time .

in System.Web.HttpContext.Current.Cache getting all cache key and data based on key as per client requirement how to get and display exact cache expire Date and Time.

System.Web.HttpContext.Current.Cache.Get("DataBadge").

Developer technologies ASP.NET ASP.NET Core
Developer technologies ASP.NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-09-19T09:27:33.317+00:00

    Hi @Bhuwan ,
    You can try storing expired values in the values of cached objects and using the same values for caching as expired values.

    var expiry = DateTime.UtcNow.AddMinutes(10);  
    HttpRuntime.Cache.Insert("key", new { Value = "Value", Expiry = expiry }, null, expiry, Cache.NoSlidingExpiration);  
    

    When you need to check the expiration time, you can get the expiration properties of the object.

    dynamic cachedData = HttpRuntime.Cache.Get("key");  
    DateTime cacheExpiry = cachedData.Expiry;  
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.