Caching

Redis Caching in .NET with IDistributedCache, HybridCache and Atomic TTLs

ServiceStack Blog demis@servicestack.com (Demis)
Caching

ServiceStack.Redis v10.5 wraps your Redis in ASP.NET Core's IDistributedCache and HybridCache, writes values and expiries in one atomic step, and adds GETEX, GETDEL and per-field hash TTLs. One pipeline behavior changes on upgrade.

Key points

  • The net10.0 build of ServiceStack.Redis backs IDistributedCache and HybridCache without an extra package.
  • Set, Add and Replace now write value and expiry in one SET ... PXAT call on Redis 6.2+.
  • Async AddAsync/ReplaceAsync used to drop their TimeSpan expiry; those keys now get a real TTL.
  • GetAndExpireValue (GETEX) and GetAndDeleteValue (GETDEL) read and expire or delete in one round trip.
  • UnlinkByPatternAsync walks the keyspace with SCAN and deletes in bounded batches instead of blocking KEYS.
  • Pipeline reads of empty strings now return "" instead of null; a config flag restores the old behavior.

Real-world use

  • A chat room that shows who is online by expiring each member's presence field 30 seconds after their last heartbeat.
  • One-time tokens such as password resets or invite links, where exactly one of two concurrent requests may redeem the value.
  • A shared 100 requests/minute API limit across several servers behind a load balancer, enforced by one atomic INCR plus PEXPIRE script.
  • Sliding sessions whose expiry is pushed back by the same command that reads them.

This summary was generated by the agent from the original post on ServiceStack Blog. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message