FusionCache icon indicating copy to clipboard operation
FusionCache copied to clipboard

Feature: NATS Backplane

Open stebet opened this issue 5 months ago • 1 comments

Added a NATS Backplane

I added a new project which uses NATS as a backplane for cache events. It's relatively straightforward

Reduced allocations for backplane messages

I also noticed some easy improvements that could be made to drastically reduce allocations for Backplane message, so I did a few things.

  • BackplaneMessage is now a readonly struct instead of a class which means it can be allocated on the stack
  • BackplaneMessage now has a TryParse static method which tries to deserialize a ReadOnlySpan<byte> into a BackplaneMessage and now provides an instance method WriteTo which serializes the BackplaneMessage to an IBufferWriter<byte> with no allocations.

Made Backplane Tests easily extensible

I made the L1BackplaneTests and the L1L2BackplaneTests abstract classes which can easily be inherited and implement methods to provide the IFusionCacheBackplane and the IDistributedCache so tests for new backplane and Distributed Caches can easily be implemented.

This could be further improved by making these test classes perhaps take the Backplane and Distributed cache as parameters for parameterized tests. I might look at doing it like that to make it even easier.

stebet avatar May 25 '25 22:05 stebet