using JSMachine.DCS.Infrastructure; using JSMachine.WMS.Common.Cache.Model; using JSMachine.WMS.Infrastructure.Helper; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JSMachine.WMS.Common.Cache { /// /// 全局文件缓存(不适用于非常频繁的存取场景,否则会造成IO开销太大的情况) /// public static class GlobalFileCache { private static string _cahcheFilePath = @$"{AppDomain.CurrentDomain.BaseDirectory}orderCache.txt"; /// /// 清空缓存 /// /// public static bool ClearOrderCache() { try { File.Delete(_cahcheFilePath); return true; } catch (Exception ex) { LogHelper.Error("清空订单缓存出错",ex); return false; } } /// /// 设置订单缓存 /// /// /// public static bool SetOrderCache(ProductionOrderCacheModel productionOrderCacheModel) { try { File.WriteAllText(_cahcheFilePath, JsonConvert.SerializeObject(productionOrderCacheModel)); return true; } catch (Exception ex) { LogHelper.Error("添加订单缓存失败",ex); return false; } } /// /// 读取当前订单缓存 /// /// public static ProductionOrderCacheModel GetCurrentOrderCache() { if (!File.Exists(_cahcheFilePath)) return null; string json = File.ReadAllText(_cahcheFilePath); if (string.IsNullOrEmpty(json)) return null; return JsonConvert.DeserializeObject(json); } } }