// //==================================================================================================== /// <summary> /// get a cache object from the cache. returns the cacheObject that wraps the object /// </summary> /// <typeparam name="returnType"></typeparam> /// <param name="key"></param> /// <returns></returns> private CacheDocumentClass getCacheDocument(string key) { CacheDocumentClass result = null; try { // - verified in createServerKey() -- key = Regex.Replace(key, "0x[a-fA-F\\d]{2}", "_").ToLowerInvariant().Replace(" ", "_"); if (string.IsNullOrEmpty(key)) { throw new ArgumentException("cache key cannot be blank"); } string serverKey = createServerKey(key); string typeMessage = ""; if (remoteCacheInitialized) { // // -- use remote cache typeMessage = "remote"; try { result = cacheClient.Get <CacheDocumentClass>(serverKey); } catch (Exception ex) { // // --client does not throw its own errors, so try to differentiate by message if (ex.Message.ToLowerInvariant().IndexOf("unable to load type") >= 0) { // // -- trying to deserialize an object and this code does not have a matching class, clear cache and return empty LogController.logWarn(core, ex); cacheClient.Remove(serverKey); result = null; } else { // // -- some other error LogController.logError(core, ex); throw; } } } if ((result == null) && core.serverConfig.enableLocalMemoryCache) { // // -- local memory cache typeMessage = "local-memory"; result = (CacheDocumentClass)MemoryCache.Default[serverKey]; } if ((result == null) && core.serverConfig.enableLocalFileCache) { // // -- local file cache typeMessage = "local-file"; string serializedDataObject = null; using (System.Threading.Mutex mutex = new System.Threading.Mutex(false, serverKey)) { mutex.WaitOne(); serializedDataObject = core.privateFiles.readFileText("appCache\\" + FileController.encodeDosFilename(serverKey + ".txt")); mutex.ReleaseMutex(); } if (!string.IsNullOrEmpty(serializedDataObject)) { result = DeserializeObject <CacheDocumentClass>(serializedDataObject); storeCacheDocument_MemoryCache(serverKey, result); } } string returnContentSegment = SerializeObject(result); returnContentSegment = (returnContentSegment.Length > 50) ? returnContentSegment.Substring(0, 50) : returnContentSegment; // // -- log result if (result == null) { LogController.logTrace(core, "miss, cacheType [" + typeMessage + "], key [" + key + "]"); } else { if (result.content == null) { LogController.logTrace(core, "hit, cacheType [" + typeMessage + "], key [" + key + "], saveDate [" + result.saveDate + "], content [null]"); } else { string content = result.content.ToString(); content = (content.Length > 50) ? (content.left(50) + "...") : content; LogController.logTrace(core, "hit, cacheType [" + typeMessage + "], key [" + key + "], saveDate [" + result.saveDate + "], content [" + content + "]"); } } // // if dependentKeyList is null, return an empty list, not null if (result != null) { // // -- empty objects return nothing, empty lists return count=0 if (result.dependentKeyList == null) { result.dependentKeyList = new List <string>(); } } } catch (Exception ex) { LogController.logError(core, ex); throw; } return(result); }
public T Get <T>(string key) { return(mc.Get <T>(key)); }
public object Get(string key) { return(Execute(() => client.Get(key))); }