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(string name, out T value) { value = default; var guid = BITAssets.Read(GetPath(name), Constant.Authentication.Token); if (guid == Guid) { value = BITAssets.Read(GetPath(name), Constant.Value); return true; } else { return true; } } public static void Write(string name, T value) { List 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()); } } }