[#20] Client: Optimize memory usage
Avoid memory allocation, use cache and static Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
parent
35fe791406
commit
0ddde467cd
46 changed files with 596 additions and 372 deletions
|
@ -2,16 +2,29 @@ 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
|
||||
{
|
||||
public static ContainerID ToGrpcMessage(this ContainerId containerId)
|
||||
private static readonly MemoryCacheEntryOptions _oneHourExpiration = new MemoryCacheEntryOptions()
|
||||
.SetSlidingExpiration(TimeSpan.FromHours(1))
|
||||
.SetSize(1);
|
||||
|
||||
public static ContainerID ToMessage(this ContainerId model)
|
||||
{
|
||||
return new ContainerID
|
||||
if (!Cache.Owners.TryGetValue(model, out ContainerID? message))
|
||||
{
|
||||
Value = ByteString.CopyFrom(Base58.Decode(containerId.Value))
|
||||
};
|
||||
message = new ContainerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(Base58.Decode(model.Value))
|
||||
};
|
||||
|
||||
Cache.Owners.Set(model, message, _oneHourExpiration);
|
||||
}
|
||||
|
||||
return message!;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue