Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
        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]);
        }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
        public void SetWithSlidingExpirationForZeroTime()
        {
            string key      = DateTime.UtcNow.Ticks.ToString() + "_SetWithSlidingExpirationForZeroTime_SetTest";
            object expected = new object();

            ExceptionAssert.ThrowsArgGreaterThan(() => WebCache.Set(key, expected, 0), "minutesToCache", "0");
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 public bool Set(string key, KeyValuePair <string, DateTime> value)
 {
     lock (locker)
     {
         WebCache.Set(key, value, 100);
         allKeys.Add(key);
         return(true);
     }
 }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
 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>);
 }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        public ActionResult WebCacheView()
        {
            var bigObject = WebCache.Get("TW MVC");

            if (bigObject == null)
            {
                bigObject = new Object();
                WebCache.Set("TW MVC", bigObject);
            }
            return(View(bigObject));
        }
Esempio n. 16
0
        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));
        }
Esempio n. 17
0
 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));
         }
     }
 }
Esempio n. 18
0
        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);
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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());
        }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
        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);
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 29
0
        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);
        }
Esempio n. 30
0
    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);
    }