Skip to content

Commit

Permalink
Revert "Better perf thanks to RecyclableMemoryStreamManager"
Browse files Browse the repository at this point in the history
This reverts commit ce70746.
  • Loading branch information
jodydonetti committed May 19, 2024
1 parent 92b75b8 commit 03009d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.IO;
using System.Threading.Tasks;
using ServiceStack.Text;

namespace ZiggyCreatures.Caching.Fusion.Serialization.ServiceStackJson;
Expand All @@ -9,8 +10,6 @@ namespace ZiggyCreatures.Caching.Fusion.Serialization.ServiceStackJson;
public class FusionCacheServiceStackJsonSerializer
: IFusionCacheSerializer
{
private static readonly RecyclableMemoryStreamManager _manager = new RecyclableMemoryStreamManager();

static FusionCacheServiceStackJsonSerializer()
{
JsConfig.Init(new Config
Expand All @@ -22,7 +21,7 @@ static FusionCacheServiceStackJsonSerializer()
/// <inheritdoc />
public byte[] Serialize<T>(T? obj)
{
using var stream = _manager.GetStream();
using var stream = new MemoryStream();

JsonSerializer.SerializeToStream<T?>(obj, stream);

Expand All @@ -32,7 +31,7 @@ public byte[] Serialize<T>(T? obj)
/// <inheritdoc />
public T? Deserialize<T>(byte[] data)
{
using var stream = _manager.GetStream(data);
using var stream = new MemoryStream(data);

return JsonSerializer.DeserializeFromStream<T?>(stream);
}
Expand All @@ -44,10 +43,8 @@ public ValueTask<byte[]> SerializeAsync<T>(T? obj)
}

/// <inheritdoc />
public async ValueTask<T?> DeserializeAsync<T>(byte[] data)
public ValueTask<T?> DeserializeAsync<T>(byte[] data)
{
using var stream = _manager.GetStream(data);

return await JsonSerializer.DeserializeFromStreamAsync<T?>(stream);
return new ValueTask<T?>(Deserialize<T>(data));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<RootNamespace>ZiggyCreatures.FusionCache.Serialization.ServiceStackJson</RootNamespace>
<DocumentationFile>ZiggyCreatures.FusionCache.Serialization.ServiceStackJson.xml</DocumentationFile>
<PackageReleaseNotes>
- Perf: better perf thanks to RecyclableMemoryStreamManager
- Updated: package dependencies
</PackageReleaseNotes>
</PropertyGroup>
Expand Down

0 comments on commit 03009d1

Please sign in to comment.