private static string GetShortenedUrl(string pageLinkBack) { if (String.IsNullOrEmpty(BitlyLogin) || String.IsNullOrEmpty(BitlyApiKey)) { return(pageLinkBack); } string encodedPageLinkBack = HttpUtility.UrlEncode(pageLinkBack); string key = "Bitly_pageLinkBack_" + BitlyApiKey + "_" + encodedPageLinkBack; string shortUrl = WebCache.Get(key) as string; if (shortUrl != null) { return(shortUrl); } string bitlyReq = "http://api.bit.ly/v3/shorten?format=txt&longUrl=" + encodedPageLinkBack + "&login="******"&apiKey=" + BitlyApiKey; try { shortUrl = GetWebResponse(bitlyReq); } catch (WebException) { return(pageLinkBack); } if (shortUrl != null) { WebCache.Set(key, shortUrl); return(shortUrl); } return(pageLinkBack); }
private bool IsSendingDataCache(NotifyOrderEntity orderEnt, string messageType) { try { bool ret = false; string orderNo = SetMessageKey(orderEnt, messageType); string cacheKey = string.Format(CacheKeys.HasReceivedMessage_Arg2, orderNo, messageType); if (!HasReceived(cacheKey)) { WebCache.Set(cacheKey, "1", DateTime.Now.AddSeconds(CacheKeys.HasReceivedMessage_TimeOut)); ret = false; } else { ret = true; } return(ret); } catch (Exception ex) { string errMsg = "本地缓å˜å‡ºçŽ°å¼‚常:" + typeof(DataCache).GetType().Name + ", " + ex.GetString(); Process.Error("本地缓å˜", "DataCache.Set", orderEnt.OrderNo, errMsg, ""); return(false); } }
public static T GetDataByKey <T>(Func <T> dataResolver, string getKey) { string key = typeof(Dictionary <string, T>).Name + typeof(string).Name + typeof(T).Name; Dictionary <string, T> data = WebCache.Get(key); if (data == null) { data = new Dictionary <string, T> { { getKey, dataResolver() } }; if (data[getKey] != null) { WebCache.Set(key, data, 2, false); } } else { if (!data.ContainsKey(getKey)) { data[getKey] = dataResolver(); if (data[getKey] != null) { WebCache.Set(key, data, 2, false); } } } return(data[getKey]); }
private static string GetShortenedUrl(string pageLinkBack) { if (!BitlyLogin.IsEmpty() && !BitlyApiKey.IsEmpty()) { string str = HttpUtility.UrlEncode(pageLinkBack); string key = "Bitly_pageLinkBack_" + BitlyApiKey + "_" + str; string webResponse = WebCache.Get(key) as string; if (webResponse != null) { return(webResponse); } string address = "http://api.bit.ly/v3/shorten?format=txt&longUrl=" + str + "&login="******"&apiKey=" + BitlyApiKey; try { webResponse = GetWebResponse(address); } catch (WebException) { return(pageLinkBack); } if (webResponse != null) { WebCache.Set(key, webResponse, 20, true); return(webResponse); } } return(pageLinkBack); }
public void SetWithSlidingExpirationForZeroTime() { string key = DateTime.UtcNow.Ticks.ToString() + "_SetWithSlidingExpirationForZeroTime_SetTest"; object expected = new object(); ExceptionAssert.ThrowsArgGreaterThan(() => WebCache.Set(key, expected, 0), "minutesToCache", "0"); }
public JsonResult GetExternalInfos(int id) { var backOffice = new Business.BackOffice(); Location location = backOffice.Locations.FirstOrDefault(l => l.Id == id); FoursquareVenue cacheItemFoursquare = null; if (!string.IsNullOrWhiteSpace(location.FoursquareID)) { string cacheKeyFoursquare = "foursquare-venue-" + location.FoursquareID; cacheItemFoursquare = (FoursquareVenue)WebCache.Get(cacheKeyFoursquare); if (cacheItemFoursquare == null) { cacheItemFoursquare = new FoursquareVenue(location.FoursquareID); WebCache.Set(cacheKeyFoursquare, cacheItemFoursquare, 1440); // one day cache } } GoogleNearby cacheItemGoogle = null; string cacheKeyGoogle = "google-nearby-" + location.Id; cacheItemGoogle = (GoogleNearby)WebCache.Get(cacheKeyGoogle); if (cacheItemGoogle == null) { cacheItemGoogle = new GoogleNearby(location.Latitude, location.Longitude); WebCache.Set(cacheKeyGoogle, cacheItemGoogle, 1440); // one day cache } return(Json(new LocationExternal(cacheItemFoursquare, cacheItemGoogle), JsonRequestBehavior.AllowGet)); }
public void SetWithSlidingExpirationForMoreThanYear() { string key = DateTime.UtcNow.Ticks.ToString() + "_SetWithSlidingExpirationForMoreThanYear_SetTest"; object expected = new object(); ExceptionAssert.ThrowsArgLessThanOrEqualTo(() => WebCache.Set(key, expected, 365 * 24 * 60 + 1, true), "minutesToCache", (365 * 24 * 60).ToString()); }
public static void SetToken(Guid token, Guid userid, string[] uts, DateTime expirationTime) { ClearToken(token); var t = new Token(userid, expirationTime, uts); WebCache.Set(token.ToString(), t, ExpirationTime); }
public bool Set(string key, KeyValuePair <string, DateTime> value) { lock (locker) { WebCache.Set(key, value, 100); allKeys.Add(key); return(true); } }
public void CanSetWithSlidingExpiration() { string key = DateTime.UtcNow.Ticks.ToString() + "_CanSetWithSlidingExpiration_SetTest"; object expected = new object(); WebCache.Set(key, expected, slidingExpiration: true); object actual = WebCache.Get(key); Assert.IsTrue(expected == actual); }
public static List <Category> GetCategoriesFromCache() { // Cache boş ise veritabanından çek ve cache'i Category listesi ile doldur if (WebCache.Get("categoryCacheList") == null) { CategoryManager categoryManager = new CategoryManager(); WebCache.Set("categoryCacheList", categoryManager.List(), 30, true); } return(WebCache.Get("categoryCacheList") as List <Category>); }
public void SetWithSlidingExpirationForYear() { string key = DateTime.UtcNow.Ticks.ToString() + "_SetWithSlidingExpirationForYear_SetTest"; object expected = new object(); WebCache.Set(key, expected, 365 * 24 * 60, true); object actual = WebCache.Get(key); Assert.IsTrue(expected == actual); }
public ActionResult WebCacheSample(string c) { var time = WebCache.Get("TW MVC"); if (time == null || c == "1") { time = DateTime.Now; WebCache.Set("TW MVC", time); } return(View(time)); }
private IList <MoneyViewModel> GetMoneyListSource(int?year, int?month) { IList <MoneyViewModel> source = WebCache.Get(MoneyListCacheName); if (source == null) { source = _accountService.GetMonthData(year, month); WebCache.Set(MoneyListCacheName, source); } return(source); }
public ActionResult WebCacheView() { var bigObject = WebCache.Get("TW MVC"); if (bigObject == null) { bigObject = new Object(); WebCache.Set("TW MVC", bigObject); } return(View(bigObject)); }
public void RemoveRemovesValueFromCacheTest() { string key = DateTime.UtcNow.Ticks.ToString() + "_RemoveTest2"; List <string> expected = new List <string>(); WebCache.Set(key, expected); var removed = WebCache.Remove(key); Assert.AreEqual(null, WebCache.Get(key)); }
public void UpdateLastUsed(string key) { lock (locker) { var value = WebCache.Get(key); if ((object)value != null) { KeyValuePair <string, DateTime> item = ((KeyValuePair <string, DateTime>)value); WebCache.Set(key, new KeyValuePair <string, DateTime>(item.Key, DateTime.Now)); } } }
public static List <Foot> GetFootsFromCache() { var result = WebCache.Get("foot-cache"); if (result == null) { FootManager footManager = new FootManager(); result = footManager.List(); WebCache.Set("foot-cache", result, 20, true); } return(result); }
public static List <PersonnelPositions> GetPersonnelPositionsFromCache() { var personnelPositions = WebCache.Get("personnelpositions-cache"); if (personnelPositions == null) { PersonnelPositionManager personnelPositionManager = new PersonnelPositionManager(); personnelPositions = personnelPositionManager.ListQueryable().OrderByDescending(m => m.CreatedOnDatetime).ToList(); WebCache.Set("personnelpositions-cache", personnelPositions, 60, true); } return(personnelPositions); }
public static List <OtherPosition> GetOtherPositionsFromCache() { var result = WebCache.Get("otherposition-cache"); if (result == null) { OtherPositionManager otherPositionManager = new OtherPositionManager(); result = otherPositionManager.List(); WebCache.Set("otherposition-cache", result, 20, true); } return(result); }
public static List <Category> GetCategoriesFromCache() { var categoryList = WebCache.Get("category-cache"); if (categoryList == null) { CategoryManager cm = new CategoryManager(); categoryList = cm.List(); WebCache.Set("category-cache", categoryList, 20, true); } return(categoryList); }
public List <Category> Get() { var cache = WebCache.Get("CategoryList"); if (cache == null) { cache = _categoryService.GetAllCategories(); WebCache.Set("CategoryList", cache, 60, true); } return(cache); }
// GET: WebCache public ActionResult Index() { string time = WebCache.Get("zaman"); if (string.IsNullOrEmpty(time)) { time = DateTime.Now.ToString(); WebCache.Set(key: "zaman", value: time, minutesToCache: 1, slidingExpiration: true); } ViewBag.simdi = time; return(View()); }
public void SetWithAbsoluteExpirationDoesNotThrow() { string key = DateTime.UtcNow.Ticks.ToString() + "SetWithAbsoluteExpirationDoesNotThrow_SetTest"; object expected = new object(); int minutesToCache = 10; bool slidingExpiration = false; WebCache.Set(key, expected, minutesToCache, slidingExpiration); object actual = WebCache.Get(key); Assert.IsTrue(expected == actual); }
public static IQueryable <Comment> GetBooksFromCache() { var result = WebCache.Get("book-cache"); if (result == null) { CommentManager commentManager = new CommentManager(); result = commentManager.ListQueryable().Include("Book").Where(x => x.IsActive == true).OrderByDescending(x => x.CreatedOn).Take(5); WebCache.Set("category-cache", result, 20, true); } return(result); }
public static List <Product> GetProductsFromCache() { var result = WebCache.Get("products-cache"); if (result == null) { ProductManager prdManager = new ProductManager(); result = prdManager.List(); WebCache.Set("products-cache", result, 20, true); } return(result); }
public void GetReturnsExpectedValueTest() { string key = DateTime.UtcNow.Ticks.ToString() + "_GetTest"; List <string> expected = new List <string>(); WebCache.Set(key, expected); var actual = WebCache.Get(key); Assert.AreEqual(expected, actual); Assert.AreEqual(0, actual.Count); }
public static List <Category> GetCategoriesFromCache() { var result = WebCache.Get("category-cache"); if (result == null) { CategoryManager categoryManager = new CategoryManager(); result = categoryManager.List(); WebCache.Set("category-cache", result, 20, true); } return(result); }
public void RemoveRemovesRightValueTest() { string key = DateTime.UtcNow.Ticks.ToString() + "_RemoveTest"; List <string> expected = new List <string>(); WebCache.Set(key, expected); var actual = WebCache.Remove(key); Assert.AreEqual(expected, actual); Assert.AreEqual(0, actual.Count); }
public static dynamic Find(string slug) { var show = WebCache.Get(slug); if (show == null) { var db = Database.Open("TDL"); var selectQueryString = "SELECT * FROM Articles WHERE slug = @0"; show = db.QuerySingle(selectQueryString, slug); WebCache.Set(slug, show, 1000, true); } return(show); }