Skip to content

Request: upsert with asynchronous guard #73

@pierrebelzile

Description

@pierrebelzile

I’m looking at switching from moka to this. My benchmarks are amazing! Thanks so much.

One use case I have is to replace an invalid value in the cache.

I can do a get to retrieve the value. Then notice that invalid. (That’s occurs because we received a cache invalidation message with a generation/timestamp and stored that in the cache.) The cache invalid value is the minimum generation to accept from the reading the value from a network cache.

At this point there is no function that I can see that will let me atomically replace the value with a guard that ensures a single compute. I simulate it with a remove + get_value_or_guard_async. However that leaves a small window where another reader finds nothing in the cache and hence has no idea about the minimum generation to accept from the network cache.

Does that make sense or am I missing something?

It seems to me that after the retrieval of the invalid value or failing to retrieve a value, I would like to call something like cache.upsert_guard_async to compute and overwrite the invalid value or insert when nothing present.

If you agree, I can take a look at creating a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions