using Microsoft.Extensions.Caching.Distributed; using Volo.Abp.Caching; namespace FoodLabeling.Application.Helpers; /// /// 平台「系统编辑」时间戳缓存项(任意业务写接口成功后更新,供 my-menuslastUpdated 使用)。 /// public class SystemEditStampCacheItem { public DateTime At { get; set; } } /// /// 全局系统编辑时间戳缓存键(单实例,不按用户区分)。 /// public class SystemEditStampCacheKey { public override string ToString() => "FoodLabeling:SystemEditStamp"; } /// /// 读写平台系统编辑时间戳。 /// public static class SystemEditStampCacheHelper { private static readonly DistributedCacheEntryOptions DefaultOptions = new() { AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(3650) }; private static readonly SystemEditStampCacheKey GlobalKey = new(); public static async Task GetAsync( IDistributedCache cache) { var item = await cache.GetAsync(GlobalKey); return item?.At; } public static async Task TouchAsync( IDistributedCache cache) { await cache.SetAsync( GlobalKey, new SystemEditStampCacheItem { At = DateTime.Now }, DefaultOptions); } }