ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.87k stars 96 forks source link

[FEATURE] StringDecrement/IncrementAsync (atomicity) #316

Closed rf-0 closed 1 month ago

rf-0 commented 1 month ago

Problem

Need atomic support for increment / decrementing values.

Solution

To be able to use something similar to redis.StringDecrementAsync and redis.StringIncrementAsync.

Alternatives

  1. Distributed lock, but slows everything down.
  2. For count values that use increment / decrement, use redis directly instead to store and read the values, however, lose the benefits of FusionCache L1+L2 backplane, so all writes and reads hit L2 (redis) all the time.

Additional context

Performance is imperative.

Question: If this is not possible for any reason, do you guys have a workaround? If I try to extend IFusionCache and use the redis methods it wont work since FusionCache is applying its own serialisation customisation to the cached data.

jodydonetti commented 1 month ago

Hi @rf-0 , FusionCache is a cache, and I don't think it's suitable for it to have an atomic counter.

I would just use StringIncrement/StringDecrement.

At most, as an optimization, I would reuse the same IConnectionMultiplexer, both directly and passed to RedisCache to save 1 connection, but that's it.

Hope this helps, let me know.