public CharacterNotifications GetNotifications(string characterId) { CharacterNotifications notifications = null; if (mCache.TryGetNotification(characterId, out notifications)) { return(notifications); } notifications = mApplication.DB.Notifications.FindOne(Query <CharacterNotifications> .EQ(n => n.characterId, characterId)); if (notifications != null) { mCache.SetNotification(notifications); mCache.ForceSave(characterId, mApplication.DB.Notifications); return(notifications); } notifications = new CharacterNotifications { characterId = characterId, notifications = new Dictionary <string, Notification>() }; mApplication.DB.Notifications.Save(notifications); mCache.SetNotification(notifications); mCache.ForceSave(characterId, mApplication.DB.Notifications); return(notifications); }
public bool TryGetNotification(string characterId, out CharacterNotifications notification) { DbObjectWrapper <CharacterNotifications> wrapper = null; if (cache.TryGetValue(characterId, out wrapper)) { notification = wrapper.Data; return(true); } notification = null; return(false); }
public void SetNotification(CharacterNotifications notification) { bool success = true; if (cache.ContainsKey(notification.characterId)) { DbObjectWrapper <CharacterNotifications> oldNotification = null; if (!cache.TryRemove(notification.characterId, out oldNotification)) { success = false; } } if (success) { cache.TryAdd(notification.characterId, new DbObjectWrapper <CharacterNotifications> { Changed = true, Data = notification }); } }