Rename project, namespaces and class names Signed-off-by: Pavel Gross <p.gross@yadro.com>
54 lines
No EOL
1.3 KiB
C#
54 lines
No EOL
1.3 KiB
C#
using System;
|
|
|
|
using FrostFS.Refs;
|
|
using FrostFS.SDK.Cryptography;
|
|
|
|
using Google.Protobuf;
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
namespace FrostFS.SDK.Client.Mappers.GRPC;
|
|
|
|
public static class OwnerIdMapper
|
|
{
|
|
private static readonly MemoryCacheEntryOptions _oneHourExpiration = new MemoryCacheEntryOptions()
|
|
.SetSlidingExpiration(TimeSpan.FromHours(1))
|
|
.SetSize(1);
|
|
|
|
public static OwnerID ToMessage(this FrostFsOwner model)
|
|
{
|
|
if (model is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
|
|
if (!Caches.Owners.TryGetValue(model, out OwnerID? message))
|
|
{
|
|
message = new OwnerID
|
|
{
|
|
Value = ByteString.CopyFrom(model.ToHash())
|
|
};
|
|
|
|
Caches.Owners.Set(model, message, _oneHourExpiration);
|
|
}
|
|
|
|
return message!;
|
|
}
|
|
|
|
public static FrostFsOwner ToModel(this OwnerID message)
|
|
{
|
|
if (message is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(message));
|
|
}
|
|
|
|
if (!Caches.Owners.TryGetValue(message, out FrostFsOwner? model))
|
|
{
|
|
model = new FrostFsOwner(Base58.Encode(message.Value.ToByteArray()));
|
|
|
|
Caches.Owners.Set(message, model, _oneHourExpiration);
|
|
}
|
|
|
|
return model!;
|
|
}
|
|
} |