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!; } }