You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, the only supported way to serialize objects for storage in FusionCache is by converting them into byte arrays using IFusionCacheSerializer. This design decision was based on the method signatures of IDistributedCache, which only accept byte arrays.
With the introduction of HybridCache, a new interface, IBufferDistributedCache, was added. This interface extends IDistributedCache and introduces methods that utilize IBufferWriter<byte> and ReadOnlySequence<byte> for read and write operations, respectively.
Existing libraries, such as Microsoft.Extensions.Caching.StackExchangeRedis, have already adopted IBufferDistributedCache, benefiting from reduced memory allocations and improved performance. However, FusionCache currently does not leverage this interface internally and still relies on IDistributedCache.
The excessive use of byte arrays can contribute to increased GC pressure. By adopting IBufferDistributedCache, FusionCache could mitigate this issue, leading to more efficient serialization and deserialization processes.
Solution
FusionCache should support IBufferDistributedCache as an alternative to IDistributedCache. This would allow for more efficient serialization, reducing memory overhead and improving performance. The internal implementation should be updated to detect and use IBufferDistributedCache when available, while maintaining compatibility with existing implementations relying on IDistributedCache.
Implementing this feature would eliminate the need for the changes introduced in PR #349 and simplify the code.
Another important interface to consider is IHybridCacheSerializer<T>. When a user registers a custom serializer that implements this interface:
Problem
Right now, the only supported way to serialize objects for storage in FusionCache is by converting them into byte arrays using
IFusionCacheSerializer
. This design decision was based on the method signatures ofIDistributedCache
, which only accept byte arrays.With the introduction of
HybridCache
, a new interface,IBufferDistributedCache
, was added. This interface extendsIDistributedCache
and introduces methods that utilizeIBufferWriter<byte>
andReadOnlySequence<byte>
for read and write operations, respectively.Existing libraries, such as
Microsoft.Extensions.Caching.StackExchangeRedis
, have already adoptedIBufferDistributedCache
, benefiting from reduced memory allocations and improved performance. However, FusionCache currently does not leverage this interface internally and still relies onIDistributedCache
.The excessive use of byte arrays can contribute to increased GC pressure. By adopting
IBufferDistributedCache
, FusionCache could mitigate this issue, leading to more efficient serialization and deserialization processes.Solution
FusionCache should support
IBufferDistributedCache
as an alternative toIDistributedCache
. This would allow for more efficient serialization, reducing memory overhead and improving performance. The internal implementation should be updated to detect and useIBufferDistributedCache
when available, while maintaining compatibility with existing implementations relying onIDistributedCache
.Implementing this feature would eliminate the need for the changes introduced in PR #349 and simplify the code.
Another important interface to consider is
IHybridCacheSerializer<T>
. When a user registers a custom serializer that implements this interface:FusionCache should recognize and utilize it within its serializer implementation via internal adapter.
Additional Context
Check out the official docs on
IBufferDistributedCache
for more details: Microsoft Docs.The text was updated successfully, but these errors were encountered: