public void test48_A() { string key = DateTime.Now.Ticks.ToString(); _objCache.Write(key, _testData); var reply = _objCache.Read <Dictionary <string, dynamic> >(key); Assert.AreEqual(_testData, reply); }
/// <summary> /// Write data to cache & disk /// </summary> /// <param name="key"></param> /// <param name="data"></param> /// <returns></returns> public bool Write(string key, Dictionary <string, dynamic> data) { if (!data.Any()) { return(false); } if (!store(key, data)) { return(false); } return(_cache.Write(key, data).Any()); }
/// <summary> /// Device Detect /// </summary> /// <param name="data">Data for device detection : HTTP Headers usually</param> /// <returns>true on success, false otherwise. Use getReply to inspect results on success.</returns> public bool DeviceDetect(Dictionary <string, dynamic> data = null) { int id = 0; if (data == null || !data.Any() || !data.ContainsKey("id")) { id = Convert.ToInt32(Config["site_id"]); } else { id = Convert.ToInt32(data["id"]); } Dictionary <string, dynamic> requestBody = new Dictionary <string, dynamic>(); foreach (KeyValuePair <string, dynamic> item in data) { if (requestBody.ContainsKey(item.Key.ToLower())) { requestBody[item.Key.ToLower()] = item.Value; } else { requestBody.Add(item.Key.ToLower(), item.Value); } } string fastKey = ""; // If caching enabled then check cache if (Cacherequests) { IOrderedEnumerable <dynamic> headersKeys = requestBody.Values.Select(c => c).OrderBy(c => c); fastKey = Jss.Serialize(headersKeys).Replace(" ", ""); Dictionary <string, dynamic> objReply = _cache.Read <Dictionary <string, dynamic> >(fastKey); if (objReply != null && objReply.Count > 0) { Reply = objReply; SetRawReply(); return(SetError(0, "OK")); } } try { bool result = false; if (UseLocal) { result = _device.LocalDetect(requestBody); // Log unknown headers if enabled SetError(_device.GetStatus(), _device.GetMessage()); } else { result = Remote(string.Format("/device/detect/{0}", id), requestBody); } if (Cacherequests) { _cache.Write(fastKey, GetReply()); } return(result); } catch (Exception ex) { SetError(299, "Exception : " + ex.Message + " " + ex.StackTrace); return(false); } }