1
This commit is contained in:
52
Core/Cache/BITCache.cs
Normal file
52
Core/Cache/BITCache.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user