/// <summary> /// QPAgentAnchorDB数据库操作 /// </summary> /// <returns></returns> public static SqlSugarClient GetInstance() { ICacheService cacheService = null; if (_RedisCache) { cacheService = new RedisCache(_RedisHost, _RedisPort); } else { cacheService = new HttpRuntimeCache(); } SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = QPAgentAnchorDB, DbType = DbType.SqlServer, InitKeyType = InitKeyType.Attribute,//InitKeyType 是读取主键和自增列信息的方式 IsAutoCloseConnection = true, ConfigureExternalServices = new ConfigureExternalServices() { SqlFuncServices = ExtMethods.GetExpMethods, DataInfoCacheService = cacheService } }); return(db); }
public static CustUserInfo GetPersonInfo(string userid, List <CustUserInfo> userinfos) { var userKey = string.Format(Redis_UserId, userid); CustUserInfo person = null; var user = string.Empty; if (WoyaopaoConfig.UseRedis) { //user = AliRedisClient.getRedisConn().GetDatabase().StringGet(userKey); user = HttpRuntimeCache.GetCache(userKey) as string; } if (string.IsNullOrWhiteSpace(user)) { var userinfo = userinfos.Where(s => s.userid == userid).FirstOrDefault(); if (userinfo != null) { person = userinfo; if (WoyaopaoConfig.UseRedis) { HttpRuntimeCache.SetCache(userKey, JsonConvert.SerializeObject(person), WoyaopaoConfig.Redis_Overtime); //AliRedisClient.getRedisConn().GetDatabase().StringSet(userKey, JsonConvert.SerializeObject(person)); } } } else { person = JsonConvert.DeserializeObject <CustUserInfo>(user); } return(person); }
public User PostExport(User user) { var key = Guid.NewGuid().ToString(); user.Id = key; HttpRuntimeCache.Set(key, user); return(user); }
public void Can_remove() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put("test_key", state); Assert.That(httpCache.Get<string>("test_key"), Is.EqualTo(state)); httpCache.Remove<string>("test_key"); Assert.That(httpCache.Get<string>("test_key"), Is.Null); }
public void Put_with_absolute_expiration_removes_key_after_expiration_period() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put("test_key", state, DateTime.Now.AddMilliseconds(500)); Thread.Sleep(TimeSpan.FromMilliseconds(800)); Assert.That(httpCache.Get <string>("test_key"), Is.Null); }
public void Can_get() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put("test_key", "test"); var returned = httpCache.Get<string>("test_key"); Assert.That(returned, Is.Not.Null); Assert.That(returned, Is.EqualTo(state)); }
public void Can_remove_state_with_default_key() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put(state); Assert.That(httpCache.Get<string>(), Is.EqualTo(state)); httpCache.Remove<string>(); Assert.That(httpCache.Get<string>(), Is.Null); }
/// <summary> /// QPVideoAnchorDB数据库操作 /// </summary> /// <returns></returns> public static SqlSugarClient GetSqlSugarDB(DbConnType type) { var strConnectionString = ""; switch (type) { case DbConnType.QPAgentAnchorDB: strConnectionString = ConfigurationManager.AppSettings["QPAgentAnchorDB"]; break; case DbConnType.QPVideoAnchorDB: strConnectionString = ConfigurationManager.AppSettings["QPVideoAnchorDB"]; break; case DbConnType.QPAnchorRecordDB: strConnectionString = ConfigurationManager.AppSettings["QPAnchorRecordDB"]; break; case DbConnType.MovieDB: strConnectionString = ConfigurationManager.AppSettings["MovieRecordDb"]; break; case DbConnType.AnchorPersonaliseDb: strConnectionString = ConfigurationManager.AppSettings["AnchorPersonaliseDb"]; break; default: strConnectionString = ConfigurationManager.AppSettings["QPVideoAnchorDB"]; break; } ICacheService cacheService = null; if (_RedisCache) { cacheService = new RedisCache(_RedisHost, _RedisPort); } else { cacheService = new HttpRuntimeCache(); } SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = strConnectionString, DbType = DbType.SqlServer, InitKeyType = InitKeyType.Attribute,//InitKeyType 是读取主键和自增列信息的方式 IsAutoCloseConnection = true, ConfigureExternalServices = new ConfigureExternalServices() { SqlFuncServices = ExtMethods.GetExpMethods, DataInfoCacheService = cacheService } }); return(db); }
public virtual void Set(string key, object value, int minutes, bool isAbsoluteExpiration, Action <string, object, string> onRemove) { HttpRuntimeCache.Set(key, value, minutes, isAbsoluteExpiration, (k, v, reason) => { if (onRemove != null) { onRemove(k, v, reason.ToString()); } }); }
public void Can_remove_state_with_default_key() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put(state); Assert.That(httpCache.Get <string>(), Is.EqualTo(state)); httpCache.Remove <string>(); Assert.That(httpCache.Get <string>(), Is.Null); }
public void Can_remove() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put("test_key", state); Assert.That(httpCache.Get <string>("test_key"), Is.EqualTo(state)); httpCache.Remove <string>("test_key"); Assert.That(httpCache.Get <string>("test_key"), Is.Null); }
public void Can_get() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put("test_key", "test"); var returned = httpCache.Get <string>("test_key"); Assert.That(returned, Is.Not.Null); Assert.That(returned, Is.EqualTo(state)); }
public void Can_put_using_default_key() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put(null, state); var key = Utils.BuildFullKey<string>(null); var returned = HttpRuntime.Cache.Get(key); Assert.That(returned, Is.Not.Null); Assert.That(returned, Is.EqualTo(state)); }
public void Can_put() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put("test_key", "test"); var key = Utils.BuildFullKey<string>("test_key"); var returned = HttpRuntime.Cache.Get(key); Assert.That(returned, Is.Not.Null); Assert.That(returned, Is.EqualTo(state)); HttpRuntime.Cache.Remove(key); }
public void RefreshToken(string token) { if (!string.IsNullOrEmpty(token)) { ICacheHelper _cache = new HttpRuntimeCache(); var cache = _cache.Get(token); if (cache != null) { _cache.Add(token, cache, TimeSpan.FromMinutes(10)); } } }
public void Can_put_using_default_key() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put(null, state); var key = Utils.BuildFullKey <string>(null); var returned = HttpRuntime.Cache.Get(key); Assert.That(returned, Is.Not.Null); Assert.That(returned, Is.EqualTo(state)); }
public void Can_put() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put("test_key", "test"); var key = Utils.BuildFullKey <string>("test_key"); var returned = HttpRuntime.Cache.Get(key); Assert.That(returned, Is.Not.Null); Assert.That(returned, Is.EqualTo(state)); HttpRuntime.Cache.Remove(key); }
public ActionResult WxSignature(string url) { try { if (!AccessTokenContainer.CheckRegistered(appid)) //检查是否已经注册 { AccessTokenContainer.Register(appid, secret); //如果没有注册则进行注册 } var tokenResult = HttpRuntimeCache.GetCache("LocalAccessToken") as LocalAccessToken; var useCache = true; if (tokenResult == null || string.IsNullOrWhiteSpace(tokenResult?.access_token) || tokenResult.ExpiresTime == null || System.DateTime.Now > tokenResult.ExpiresTime) //过期 { useCache = false; var result = AccessTokenContainer.GetAccessTokenResult(appid, true); if (!string.IsNullOrWhiteSpace(result?.errmsg)) { return(Json(new { ErrMsg = JsonConvert.SerializeObject(result) }, JsonRequestBehavior.AllowGet)); //return Json(new { data = JsonConvert.SerializeObject(new { appid, secret }), ErrMsg = JsonConvert.SerializeObject(tokenResult) }, JsonRequestBehavior.AllowGet); } tokenResult = new LocalAccessToken(result) { }; HttpRuntimeCache.SetCache("LocalAccessToken", tokenResult, 7260); } var ticket = JsApiTicketContainer.GetJsApiTicket(appid); var model = new WXShare() { appId = appid, timestamp = JSSDKHelper.GetTimestamp(), nonce = JSSDKHelper.GetNoncestr(), url = Server.UrlDecode(url), ticket = ticket, //result = JsonConvert.SerializeObject(tokenResult), useCache = useCache }; model.signature = JSSDKHelper.GetSignature(ticket, model.nonce, model.timestamp, model.url); return(Json(model, JsonRequestBehavior.AllowGet)); } catch (System.Exception ex) { return(Json(new { ErrMsg = ex.Message, StackTrace = JsonConvert.SerializeObject(ex.StackTrace) }, JsonRequestBehavior.AllowGet)); } }
public static ICache <T> GetCacheProvider <T>() { ICache <T> cache = null; if (!caches.ContainsKey(typeof(T))) { cache = new HttpRuntimeCache <T>(); caches.Add(typeof(T), cache); } else { cache = caches[typeof(T)] as ICache <T>; } return(cache); }
private static void HttpRuntimeCache() { ICacheService myCache = new HttpRuntimeCache();//ICacheService SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true, ConfigureExternalServices = new ConfigureExternalServices() { DataInfoCacheService = myCache //Setting external cache service } }); db.Aop.OnLogExecuted = (s, p) => { Console.WriteLine(s); }; db.CodeFirst.InitTables <Student>(); db.Insertable(new Student() { CreateTime = DateTime.Now, Name = "a", SchoolId = 0 }).ExecuteCommand(); var x = db.Queryable <Student>().WithCache().ToDictionaryList(); // db.Queryable<Student>().Select("1 as idx").WithCache().ToList(); Console.WriteLine("Cache Key Count:" + myCache.GetAllKey <string>().Count()); foreach (var item in myCache.GetAllKey <string>()) { Console.WriteLine(); Console.WriteLine(item); Console.WriteLine(); } db.Deleteable <Student>().Where(it => it.Id == 1).RemoveDataCache().ExecuteCommand(); Console.WriteLine("Cache Key Count:" + myCache.GetAllKey <string>().Count()); }
private static void HttpRuntimeCache() { ICacheService myCache = new HttpRuntimeCache();//ICacheService SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true, ConfigureExternalServices = new ConfigureExternalServices() { DataInfoCacheService = myCache //Setting external cache service } }); for (int i = 0; i < 10000; i++) { db.Queryable <Student>().Where(it => it.Id > 0).WithCache().ToList(); } db.Queryable <Student, Student>((s1, s2) => s1.Id == s2.Id).Select(s1 => s1).WithCache().ToList(); db.Queryable <Student, Student>((s1, s2) => new object[] { JoinType.Left, s1.Id == s2.Id }).Select(s1 => s1).WithCache().ToList(); Console.WriteLine("Cache Key Count:" + myCache.GetAllKey <string>().Count()); foreach (var item in myCache.GetAllKey <string>()) { Console.WriteLine(); Console.WriteLine(item); Console.WriteLine(); } db.Deleteable <Student>().Where(it => it.Id == 1).RemoveDataCache().ExecuteCommand(); Console.WriteLine("Cache Key Count:" + myCache.GetAllKey <string>().Count()); }
public HttpResponseMessage PostExportData(string id) { // 查询条件 var user = (User)HttpRuntimeCache.Get(id); var file = GetMemoryStream(user); //string csv = _service.GetData(model); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(file) }; //a text file is actually an octet-stream (pdf, etc) //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel"); //we used attachment to force download result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = "file.xls"; return(result); }
public ActionResult RunInfo() { try { var sourceFromRedis = false; if (WoyaopaoConfig.UseRedis) { //var result = AliRedisClient.getRedisConn().GetDatabase().StringGet(WoyaopaoConfig.Redis_sourceDataKey); var result = HttpRuntimeCache.GetCache(WoyaopaoConfig.Redis_sourceDataKey) as string; if (string.IsNullOrWhiteSpace(result)) { var source = WQKHospital.GetDataFromSource(); var entity = WQKHospital.DataTransfor(source.data); var json = JsonConvert.SerializeObject(entity); HttpRuntimeCache.SetCache(WoyaopaoConfig.Redis_sourceDataKey, json, WoyaopaoConfig.Redis_Overtime); //AliRedisClient.getRedisConn().GetDatabase().StringSet(WoyaopaoConfig.Redis_sourceDataKey, json, new TimeSpan(WoyaopaoConfig.Woyaopao_source_Timespan)); return(Json(new { sourceFromRedis = sourceFromRedis, Data = entity }, JsonRequestBehavior.AllowGet)); } else { sourceFromRedis = true; var entity = JsonConvert.DeserializeObject <CustPageInfo>(result); return(Json(new { sourceFromRedis = sourceFromRedis, Data = entity }, JsonRequestBehavior.AllowGet)); } } else { var source = WQKHospital.GetDataFromSource(); var entity = WQKHospital.DataTransfor(source.data); return(Json(new { sourceFromRedis = sourceFromRedis, Data = entity }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Logger.Default.Error(ex); return(Json(new { Success = false, Msg = JsonConvert.SerializeObject(ex) }, JsonRequestBehavior.AllowGet)); } }
public void Setup() { Cache = new HttpRuntimeCache(); Cache.Insert("test1", "hello world", CacheEvictionPolicy.Empty); Cache.Insert("test2", "hello world 2", CacheEvictionPolicy.Empty); Cache.Insert("test3", "hello world 3", CacheEvictionPolicy.Empty); Cache.Insert("test4", "hello world 4", CacheEvictionPolicy.Empty); Cache.Insert("test5", "hello world 5", CacheEvictionPolicy.Empty); Cache.Insert("test6", "hello world 6", CacheEvictionPolicy.Empty); Cache.Insert("test7", "hello world 7", CacheEvictionPolicy.Empty); Cache.Insert("test8", "hello world 8", CacheEvictionPolicy.Empty); Cache.Insert("test9", "hello world 9", CacheEvictionPolicy.Empty); Cache.Insert("test10", "hello world 10", CacheEvictionPolicy.Empty); Cache.Insert("test11", "hello world 11", CacheEvictionPolicy.Empty); Cache.Insert("test12", "hello world 12", CacheEvictionPolicy.Empty); Cache.Insert("test13", "hello world 13", CacheEvictionPolicy.Empty); Cache.Insert("test14", "hello world 14", CacheEvictionPolicy.Empty); Cache.Insert("test15", "hello world", CacheEvictionPolicy.Empty); Repository = new CacheRepository(); }
public virtual void Remove(string key) { HttpRuntimeCache.Remove(key); }
public virtual object Get(string key) { return(HttpRuntimeCache.Get(key)); }
public virtual void Clear(string keyRegex) { HttpRuntimeCache.RemoveAll(keyRegex); }
public void Put_with_sliding_expiration_removes_key_after_expiration_period() { var state = "test"; var httpCache = new HttpRuntimeCache(); httpCache.Put("test_key", state, TimeSpan.FromMilliseconds(500)); Thread.Sleep(TimeSpan.FromMilliseconds(200)); Assert.That(httpCache.Get<string>("test_key"), Is.Not.Null); Thread.Sleep(TimeSpan.FromMilliseconds(800)); Assert.That(httpCache.Get<string>("test_key"), Is.Null); }