How Can I Get Expiration Time in IMemoryCache?

45 Views Asked by At

I have MemoryCacheService class in .NET 8. Then I want to get expiration time of the setted cache key. I set the value to cache with below method.

    public bool Set<T>(string key, T value, TimeSpan? expiration = null)
    {
      var options = new MemoryCacheEntryOptions();
      if (expiration.HasValue)
      {
        options.SetAbsoluteExpiration(expiration.Value);
      }

      _cache.Set(key, value, options);
      return true;
    }

I assign the expiration value using options.SetAbsoluteExpiration but IMemoryCache does not contain get expiration method. How can I get Expiration Time?

For example, If I call the set method with TimeSpan.FromMinutes(20). Then I want to reach this 20 minutes info with given key. How can I do this?

0

There are 0 best solutions below