skip to Main Content

Is it possible to utilize Redis to create a write-behind or write-through cache for .NET? Ideally a transparent cache which is written to by a single process and supports loading the missing data from a database, and persisting the dirty blocks every once in a while?

I have been googling for hours, perhaps by google-fu is too rusty, but I am unable to find anything similar, and yet it seems like a common scenario.

So I basically have two questions:

  1. Is there a way to extend Redis (or such implementation already exists) to make it forward dirty blocks in regular intervals or load missing blocks from a persistent store?

  2. If not, what would be the appropriate approach to implement in Redis:

    a) send a "request" functionality and wait for the data to appear in Redis (the writer process wants to update a block, so it notifies the data process to load the blocks into Redis, then waits for the blocks to appear in cache),

    b) the polling of dirty blocks in regular intervals by the data service (find dirty blocks, clear the dirty flag atomically, save to disk)?

2

Answers


  1. Yes, Redis supports Write Behind and Write Through Cache via RGSync, which is a RedisGears recipe. Check out the demo here.

    Other links, depending on whether you are using Enterprise or OpenSource version: https://docs.redislabs.com/latest/modules/redisgears/

    https://redis.io/modules

    Login or Signup to reply.
  2. I’m not sure I understood your question perfectly, but you may try to take a look at FusionCache ⚡🦥, a library I recently released.

    You may achieve what you want (but again, maybe I got it wrong) by using a combo of 2 features: fail-safe + advanced timeouts with background factory completion.

    In short: you can cache something for, let’s say, 2 min after which a factory would be called to refresh the data but, in case of problems (exceptions, timeouts, etc), that expired value would be used again until the factory is able to complete in the background, after which it will update the cache right away.

    The same would be valid for missing cache entries: all concurrent callers for the same cache key will be blocked and only one factory will be executed, thanks to an optimization that avoids multiple concurrent factory calls.

    Another interesting feature is support for an optional, distributed 2nd level cache, automatically managed and kept in sync with the local one for you without doing anything.

    If you will give it a chance please let me know what you think.

    /shameless-plug

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search