This commit is contained in:
CortexCore
2023-06-05 16:25:06 +08:00
parent 9027120bb8
commit 4565ff2e35
2947 changed files with 0 additions and 0 deletions

52
Core/Cache/BITCache.cs Normal file
View File

@@ -0,0 +1,52 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using BITKit;
namespace BITKit.IO
{
public class BITCache
{
public struct CacheInfo
{
public DateTime CreateTime;
public Guid Guid;
}
public static Guid Guid = Guid.NewGuid();
static string GetPath(string name) => PathHelper.GetFilePath("Cache", name);
public static bool Read<T>(string name, out T value)
{
value = default;
var guid = BITAssets.Read<Guid>(GetPath(name), Constant.Authentication.Token);
if (guid == Guid)
{
value = BITAssets.Read<T>(GetPath(name), Constant.Value);
return true;
}
else
{
return true;
}
}
public static void Write<T>(string name, T value)
{
List<BITAsset> assets = new();
assets.Add(
new(
Constant.Authentication.Token,
JsonConvert.SerializeObject(Guid)
)
);
assets.Add(
new(
Constant.Value,
JsonConvert.SerializeObject(value, Formatting.Indented)
)
);
BITAssets.Build(GetPath(name), assets.ToArray());
}
}
}