using System; namespace JiaZhiQuan.Common { public static partial class CacheKeys { /// /// 文章缓存1分钟 /// public const int PostDetailCacheSecs = 60; /// /// 文章详情缓存编号 /// public static string PostDetail(long postId) { return GenerateKey($"post_detail:{postId}"); } /// /// 1天 /// public const int PostRecommendListCacheSecs = 60 * 60 * 24; /// /// 文章推荐列表缓存的Key /// /// 当天几号 /// 非登录用户,传0 /// 如果没有,则传null /// null表示所有,1为带图片的,2为带视频的 /// 如果没有,则传null public static string PostRecommendList(int day, long userId, int? categoryType, int? contentType, bool? hasTopic) { return GenerateKey($"post_rcml_{day}:{userId}:{categoryType?.ToString() ?? "null"}_{contentType?.ToString() ?? "null"}" + (hasTopic == null ? "" : hasTopic.Value ? "_t1" : "_t0")); } public const int PostRecommendCacheCursorSecs = 60 * 60 * 48; /// /// 文章推荐缓存用户端访问的游标,内容是已取得的最后一个`{postId}_{index}_{over}` /// /// 客户端编号 /// 如果没有,则传null /// null表示所有,1为带图片的,2为带视频的 /// 如果没有,则传null public static string PostRecommendCacheCursor(string clientKey, int? categoryType, int? contentType, bool? hasTopic) { return GenerateKey($"post_rcml_cursor:{clientKey}:{categoryType?.ToString() ?? "null"}_{contentType?.ToString() ?? "null"}" + (hasTopic == null ? "" : hasTopic.Value ? "_t1" : "_t0")); } /// /// 新文章推荐缓存 /// /// 如果没有,则传null /// null表示所有,1为带图片的,2为带视频的 /// 如果没有,则传null public static string PostNewRecommendCache(string time, int? categoryType, int? contentType, bool? hasTopic) { return GenerateKey($"post_rcml_new:{time}:{categoryType?.ToString() ?? "null"}_{contentType?.ToString() ?? "null"}" + (hasTopic == null ? "" : hasTopic.Value ? "_t1" : "_t0")); } public const int PostContentCacheSecs = 20; /// /// 文章内容缓存,用于用户发布,在AI审核时优先从缓存获取 /// /// /// public static string PostContent(long postId) { return GenerateKey($"post_content:{postId}"); } public const int PostNewNotificationCacheSecs = 6 * 60 * 60; // 6小时 /// /// 发动态后,6小时内发的新动态不会通知,1个自然日最多1条 /// /// public static int PostNewNotificationCacheTime() { // 获取当前时间 DateTime currentTime = DateTime.Now; // 获取今天结束的时间(明天的凌晨) DateTime endOfDay = currentTime.Date.AddDays(1); // 计算时间差 TimeSpan timeRemaining = endOfDay - currentTime; // 获取剩余秒数 int secondsRemaining = (int)timeRemaining.TotalSeconds; // 如果剩余时间大于6小时,则返回距离今天结束剩余的秒数 if(secondsRemaining > PostNewNotificationCacheSecs) { return secondsRemaining; } // 如果剩余时间不足6小时,则返回6小时 else { return PostNewNotificationCacheSecs; } } /// /// 一个人发了动态之后,将状态缓存到Redis,判断是否需要通知 /// public static string PostNewNotification(long userId) { return GenerateKey($"post_new:{userId}"); } /// /// 一个人发了商品之后,将状态缓存到Redis,判断是否需要通知 /// public static string GoodsNewNotification(long userId) { return GenerateKey($"mall:goods_new:{userId}"); } /// /// 发商品后,1个自然日最多1条通知 /// /// public static int GoodsNewNotificationCacheTime() { // 获取当前时间 DateTime currentTime = DateTime.Now; // 获取今天结束的时间(明天的凌晨) DateTime endOfDay = currentTime.Date.AddDays(1); // 计算时间差 TimeSpan timeRemaining = endOfDay - currentTime; // 获取剩余秒数 return (int)timeRemaining.TotalSeconds; } } }