Link Search Menu Expand Document


This interface is used to make a class expirable in a contextual point of view. Is is used by CacheItem class.


Below are the methods available from this interface.

  • IsExpired - identifies whether this class is expired.


Below are the properties available from this interface.

  • CreatedDate - the creation date.
  • Expiration - the expiration date.


You can use this interface if you wish to manage the expiration lifespan of your class. The implementation must be handled manually (depends on the purpose of the usage).

How to Implement?

You have to manually create a class that implements this interface.

public class CacheItem : IExpirable
    public CacheItem(string key,
        object value,
        int expirationInMinutes)
        CreatedDate = DateTime.UtcNow;
        Expiration = CreatedDate.AddMinutes(expirationInMinutes);

    // IExpirable

    public DateTime CreatedDate { get; }

    public DateTime Expiration { get; }

    public bool IsExpired() => Expiration >= DateTime.UtcNow;