frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/Mappers/ContainerId.cs
Pavel Gross d1271df207 [#13] Client: Use code analyzers
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-09-23 19:25:59 +03:00

39 lines
No EOL
1 KiB
C#

using System;
using FrostFS.Refs;
using FrostFS.SDK.Cryptography;
using Google.Protobuf;
using Microsoft.Extensions.Caching.Memory;
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 FrostFsContainerId model)
{
if (model is null)
{
throw new ArgumentNullException(nameof(model));
}
var containerId = model.GetValue() ?? throw new ArgumentNullException(nameof(model));
if (!Cache.Containers.TryGetValue(containerId, out ContainerID? message))
{
message = new ContainerID
{
Value = ByteString.CopyFrom(Base58.Decode(containerId))
};
Cache.Containers.Set(containerId, message, _oneHourExpiration);
}
return message!;
}
}