Skip to content

[Feature Request] Allow factory method of hybrid cache to return result AND HybridCacheEntryOptions. #6142

Closed

Description

@Erwinvandervalk

When using HybridCache, there are cases where you may not know in advance if or how long a value should be cached:

Discarding a Cached Value

You retrieve a value, but the result turns out to be invalid and shouldn't be cached at all. While you could throw an exception in the factory, this is costly. Returning null isn't a solution either, as null would simply get cached.

Conditional Cache Durations

Some values inherently know how long they should remain cached. For example, when retrieving access tokens, the token itself determines its validity period, but the client may not be aware of this.

Possible solutions

One approach is to allow the factory to return a tuple containing both the result (if any) and cache options. In these cache options, you can then decide not to store any result.

Alternatively, if you only need to handle scenario #1, you can simply avoid caching null results.

Activity

  1. changed the title [-][Feature Request] Allow factory method of hybrid cache to control / set HybridCacheEntryOptions.[/-] [+][Feature Request] Allow factory method of hybrid cache to return result AND HybridCacheEntryOptions.[/+] on Mar 18, 2025
  2. Erwinvandervalk commented on Mar 18, 2025

    @Erwinvandervalk
    Author

    sorry, looks like a duplicate of: dotnet/runtime#129842

  3. locked and limited conversation to collaborators on Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions