public void SetVM(ConversationViewModel conversationVM, bool allowFlush)
        {
            if (conversationVM == null)
            {
                return;
            }
            object lockObj   = this._lockObj;
            bool   lockTaken = false;

            try
            {
                Monitor.Enter(lockObj, ref lockTaken);
                this._inMemoryCachedData[ConversationViewModelCache.GetKey(conversationVM.UserOrCharId, conversationVM.IsChat)] = conversationVM;
                if (!(this._inMemoryCachedData.Count > this._maxNumberOfInMemoryItems & allowFlush))
                {
                    return;
                }
                this.FlushToPersistentStorage();
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(lockObj);
                }
            }
        }
        public ConversationViewModel GetVM(long userOrCharId, bool isChatId, bool onlyInMemoryCache = false)
        {
            object lockObj   = this._lockObj;
            bool   lockTaken = false;

            try
            {
                Monitor.Enter(lockObj, ref lockTaken);
                string key = ConversationViewModelCache.GetKey(userOrCharId, isChatId);
                if (this._inMemoryCachedData.ContainsKey(key))
                {
                    return(this._inMemoryCachedData[key]);
                }
                if (onlyInMemoryCache)
                {
                    return(null);
                }
                ConversationViewModel conversationVM = new ConversationViewModel();
                if (!CacheManager.TryDeserialize((IBinarySerializable)conversationVM, key, CacheManager.DataType.CachedData))
                {
                    conversationVM.InitializeWith(userOrCharId, isChatId);
                }
                if (conversationVM.OutboundMessageVM == null || conversationVM.Messages == null)
                {
                    conversationVM = new ConversationViewModel();
                    conversationVM.InitializeWith(userOrCharId, isChatId);
                }
                this.SetVM(conversationVM, false);
                return(conversationVM);
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(lockObj);
                }
            }
        }
 private static string GetKey(ConversationViewModel cvm)
 {
     return(ConversationViewModelCache.GetKey(cvm.UserOrCharId, cvm.IsChat));
 }