52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
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());
|
|
}
|
|
}
|
|
} |