30 lines
No EOL
840 B
C#
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!;
|
|
}
|
|
} |