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 is the list of methods.

IsExpiredIdentifies whether this class is expired.


Below is the list of properties.

CreatedDateThe creation date.
ExpirationThe 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;