Files
speckle-sharp-sdk/src/Speckle.Sdk/Serialisation/V2/MemoryJsonCacheManager.cs
T
Adam Hathcock f163b2822e (feat) add memory serialize and make relevant tests use it (#252)
* First pass of ObjectSaver and better in-memory usage

* fix some tests

* add commit to match deserialize process

* correct more tests

* format

* make a deserialize factory

* fix tests? and format

* use distinct

* Fix mismerge

* Fix serialization issues with tests

* fix merges

* follow copilot suggestions

* remove disables
2025-04-08 10:21:47 +01:00

38 lines
1.2 KiB
C#

using System.Collections.Concurrent;
using Speckle.Sdk.SQLite;
namespace Speckle.Sdk.Serialisation.V2;
#pragma warning disable CA1063
public class MemoryJsonCacheManager(ConcurrentDictionary<Id, Json> jsonCache) : ISqLiteJsonCacheManager
#pragma warning restore CA1063
{
public IReadOnlyCollection<(string Id, string Json)> GetAllObjects() =>
jsonCache.Select(x => (x.Key.Value, x.Value.Value)).ToList();
public void DeleteObject(string id) => jsonCache.TryRemove(new Id(id), out _);
public string? GetObject(string id) => jsonCache.TryGetValue(new Id(id), out var json) ? json.Value : null;
public void SaveObject(string id, string json) => jsonCache.TryAdd(new Id(id), new Json(json));
public void UpdateObject(string id, string json) => jsonCache[new Id(id)] = new Json(json);
public virtual void SaveObjects(IEnumerable<(string id, string json)> items)
{
foreach (var (id, json) in items)
{
SaveObject(id, json);
}
}
public bool HasObject(string objectId) => jsonCache.ContainsKey(new Id(objectId));
#pragma warning disable CA1063
#pragma warning disable CA1816
public void Dispose()
#pragma warning restore CA1816
#pragma warning restore CA1063
{ }
}