Skip to content

[API Proposal]: Allow nullable DateTimeOffset / TimeSpan for IMemoryCache.Set #120971

@angelaki

Description

@angelaki

Background and motivation

Right now, wenn calling this overload, an actual value must be passed. It would be nice to allow nullable values here, since the target-property actually is.

API Proposal

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, DateTimeOffset? absoluteExpiration)
{
    using ICacheEntry entry = cache.CreateEntry(key);
    entry.AbsoluteExpiration = absoluteExpiration;
    entry.Value = value;

    return value;
}

API Usage

cache.Set(key, value, options?.absoluteExpirationRelativeToNow);

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions