public static async Task <Achievement> GetAchievementAsync(MikiContext context, long userId, string name) { string key = $"achievement:{userId}:{name}"; var cache = MikiApp.Instance.GetService <ICacheClient>(); Achievement a = await cache.GetAsync <Achievement>(key); if (a != null) { return(context.Attach(a).Entity); } Achievement achievement = await context.Achievements.FindAsync(userId, name); await cache.UpsertAsync(key, achievement); return(achievement); }
public static async Task <Achievement> GetAchievementAsync(MikiContext context, long userId, string name) { string key = $"achievement:{userId}:{name}"; if (await Global.RedisClient.ExistsAsync(key)) { Achievement a = await Global.RedisClient.GetAsync <Achievement>(key); if (a != null) { return(context.Attach(a).Entity); } } Achievement achievement = await context.Achievements.FindAsync(userId, name); await Global.RedisClient.UpsertAsync(key, achievement); return(achievement); }