RKSoftware.Packages.Caching.System.Text.Json.StreamConverter 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package RKSoftware.Packages.Caching.System.Text.Json.StreamConverter --version 3.0.0
                    
NuGet\Install-Package RKSoftware.Packages.Caching.System.Text.Json.StreamConverter -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RKSoftware.Packages.Caching.System.Text.Json.StreamConverter" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RKSoftware.Packages.Caching.System.Text.Json.StreamConverter" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RKSoftware.Packages.Caching.System.Text.Json.StreamConverter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RKSoftware.Packages.Caching.System.Text.Json.StreamConverter --version 3.0.0
                    
#r "nuget: RKSoftware.Packages.Caching.System.Text.Json.StreamConverter, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RKSoftware.Packages.Caching.System.Text.Json.StreamConverter@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RKSoftware.Packages.Caching.System.Text.Json.StreamConverter&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RKSoftware.Packages.Caching.System.Text.Json.StreamConverter&version=3.0.0
                    
Install as a Cake Tool

RKSoftware.Packages.Caching.System.Text.Json.StreamConverter

NuGet Downloads

Binary System.Text.Json serialization for RKSoftware.Packages.Caching. It contains an IObjectToStreamConverter implementation together with the registration extension that plugs it into the cache service, so cached objects are written to Redis as UTF-8 bytes and read back from a stream.

The core caching package defines how values are cached but not how they are serialized — this package supplies the missing half. Register exactly one converter package in an application.

Installation

dotnet add package RKSoftware.Packages.Caching
dotnet add package RKSoftware.Packages.Caching.System.Text.Json.StreamConverter

Getting started

Chain the converter registration onto the cache registration:

using RKSoftware.Packages.Caching.Infrastructure;
using RKSoftware.Packages.Caching.System.Text.Json.StreamConverter;

builder.Services
    .UseRKSoftwareCache(
        builder.Configuration.GetSection(nameof(RedisCacheSettings)),
        scopedKeyPrefix: "MyApp")
    .UseSystemTextJsonStreamConverter();

Nothing else is required — the ICacheService API is unchanged, only the storage format differs:

using RKSoftware.Packages.Caching.Contract;

public sealed class ReportService(ICacheService cache, IReportRepository repository)
{
    public Task<Report?> GetAsync(int id) =>
        cache.GetOrSetCachedObjectAsync(
            $"report.{id}",
            () => repository.RenderAsync(id),
            storageDuration: 600);
}

What it registers

UseSystemTextJsonStreamConverter() (namespace RKSoftware.Packages.Caching.System.Text.Json.StreamConverter) adds two scoped services:

Contract Implementation
IObjectToStreamConverter SystemTextJsonStreamConverter
ICacheRepository StreamCacheRepository

API overview

SystemTextJsonStreamConverter implements IObjectToStreamConverter:

Member Behaviour
byte[] ToBytes<T>(T obj) JsonSerializer.SerializeToUtf8Bytes of the value.
Task<T?> FromStreamAsync<T>(Stream data) JsonSerializer.DeserializeAsync over the stream; returns null when the payload deserializes to null.

FromStreamAsync<T> is constrained to where T : class, matching ICacheService. Serialization uses the System.Text.Json defaults, so annotate your models with System.Text.Json.Serialization attributes ([JsonPropertyName], [JsonIgnore], [JsonConverter]) to influence the output.

When to use this instead of a text converter

The two text converters serialize through an intermediate string; this one goes straight to and from UTF-8 bytes. For large cached objects that avoids allocating the whole JSON document as a string on every read and write, which reduces large-object-heap pressure.

For small values the difference is negligible, and the text converters produce human-readable entries that are easier to inspect with redis-cli.

Register exactly one converter package. All three register ICacheRepository, so adding more than one leaves the last registration in effect and silently changes the storage format. Values written by a text converter cannot be read back by this one, and vice versa — switching converters in an existing deployment requires flushing the affected keys.

  • NuGet — the core caching abstractions this package extends. Required.
  • NuGet — JSON string serialization with System.Text.Json.
  • NuGet — JSON string serialization with Newtonsoft.Json.

Source, issues and full documentation: github.com/rk-software-systems/rk-dn-redis-cache-provider

License

Released into the public domain under The Unlicense.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 101 9/2/2026
3.0.1 75 9/1/2026
3.0.0 84 8/30/2026
2.0.3 2,213 6/9/2023
2.0.2 516 2/8/2023
2.0.1 458 2/8/2023
2.0.0 459 2/7/2023