frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/Mappers/ContainerId.cs
Pavel Gross 6083834582 [#20] Client: Fix typo
Signed-off-by: Pavel Gross <p.gross@yando.com>
2024-08-01 18:02:59 +03:00

30 lines
No EOL
840 B
C#

using FrostFS.Refs;
using FrostFS.SDK.Cryptography;
using FrostFS.SDK.ModelsV2;
using Google.Protobuf;
using Microsoft.Extensions.Caching.Memory;
using System;
namespace FrostFS.SDK.ClientV2.Mappers.GRPC;
public static class ContainerIdMapper
{
private static readonly MemoryCacheEntryOptions _oneHourExpiration = new MemoryCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromHours(1))
.SetSize(1);
public static ContainerID ToMessage(this ContainerId model)
{
if (!Cache.Containers.TryGetValue(model, out ContainerID? message))
{
message = new ContainerID
{
Value = ByteString.CopyFrom(Base58.Decode(model.Value))
};
Cache.Containers.Set(model, message, _oneHourExpiration);
}
return message!;
}
}