public static void RemoveCategoryListFromCache()
 {
     if (WebCache.Get("CategoryList") != null)
     {
         WebCache.Remove("CategoryList");
     }
 }
Esempio n. 2
0
        public Models.Transaction GetProduct(string token)
        {
            var transaction = new Models.Transaction();

            if (WebCache.Get($"Token_{token}") == null)
            {
                transaction.IsValid = false;
                transaction.Message = "Sessão expirada";
                return(transaction);
            }


            transaction.IsValid  = true;
            transaction.Products = new List <Models.Product>
            {
                new Models.Product {
                    Id = Guid.NewGuid(), Name = "Frango", Price = 15.0m
                },
                new Models.Product {
                    Id = Guid.NewGuid(), Name = "Peixe", Price = 10.0m
                },
                new Models.Product {
                    Id = Guid.NewGuid(), Name = "Café", Price = 4.30m
                },
                new Models.Product {
                    Id = Guid.NewGuid(), Name = "Pão", Price = 1.70m
                }
            };
            return(transaction);
        }
Esempio n. 3
0
 public static void ClearToken(Guid token)
 {
     if (WebCache.Get(token.ToString()) != null)
     {
         WebCache.Remove(token.ToString());
     }
 }
Esempio n. 4
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. 5
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]);
        }
        private QueryResponse ContinueSequentialFlow(QueryRequest request)
        {
            var           processObject = (Process)WebCache.Get(request.SessionId);
            QueryResponse response      = new QueryResponse()
            {
                SessionId = request.SessionId
            };

            if (processObject == null)
            {
                return(null);
            }

            if (processObject != null)
            {
                foreach (var question in processObject.Questions)
                {
                    if (question.Intent == CurrentIntent)
                    {
                        ContinueSequentialFlowStep(ref response, question, processObject.GlobalVariables);
                    }
                }
            }

            return(response);
        }
Esempio n. 7
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. 8
0
 public KeyValuePair <string, DateTime>?Get(string key)
 {
     lock (locker)
     {
         return(WebCache.Get(key));
     }
 }
Esempio n. 9
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. 10
0
        /// <summary>
        /// 获取某业务类型下所有的下拉框
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static DataView getEnumDisplayNameList(businessType type)
        {
            object businessType = WebCache.Get("FileCache-businessType");

            if (businessType == null)
            {
                #region  初始化枚举数据
                DataTable dtData = new DataTable();
                dtData.Columns.Add("type", typeof(string));
                dtData.Columns.Add("name", typeof(string));
                dtData.Columns.Add("value", typeof(int));

                dtData.Rows.Add(new object[] { "productType", 0, "实体商品" });
                dtData.Rows.Add(new object[] { "productType", 1, "卡密商品" });
                dtData.Rows.Add(new object[] { "productType", 2, "游戏商品" });

                dtData.Rows.Add(new object[] { "productStatus", 0, "正常" });
                dtData.Rows.Add(new object[] { "productStatus", 1, "下架" });

                WebCache.Max("FileCache-businessType", dtData, new CacheDependency("businessType"));
                #endregion
            }
            DataTable dataTable = businessType as DataTable;
            DataView  dvResult  = new DataView(dataTable, string.Format("type='{0}' "), type.ToString()
                                               , DataViewRowState.CurrentRows);
            return(dvResult);
        }
Esempio n. 11
0
        public IDictionary <string, KeyValuePair <string, DateTime> > GetAll()
        {
            IDictionary <string, KeyValuePair <string, DateTime> > result =
                new Dictionary <string, KeyValuePair <string, DateTime> >();
            HashSet <string> itemsToRemove = new HashSet <string>();

            lock (locker)
            {
                foreach (var key in allKeys)
                {
                    var value = (KeyValuePair <string, DateTime>)WebCache.Get(key);
                    if (value.Value.AddMinutes(1) < DateTime.Now)
                    {
                        WebCache.Remove(key);
                        itemsToRemove.Add(key);
                    }
                    else
                    {
                        result.Add(key, value);
                    }
                }
                foreach (var itm in itemsToRemove)
                {
                    allKeys.Remove(itm);
                }
            }

            return(result);
        }
Esempio n. 12
0
        public ActionResult UpdateCategory()
        {
            string         text         = Session["text"].ToString();
            SearchResponse returnResult = WebCache.Get("searchResponse" + text);

            return(PartialView(returnResult));
        }
Esempio n. 13
0
        public ActionResult Navigate(int start, int index, string command)
        {
            string         text         = Session["text"].ToString();
            SearchResponse returnResult = new SearchResponse();
            SearchResponse result       = null;

            if (Convert.ToBoolean(Session["category"]))
            {
                result = Session["searchResponseCategory"] as SearchResponse;
            }
            else
            {
                result = WebCache.Get("searchResponse" + text);
            }
            returnResult.StartPosition   = start;
            returnResult.CurrentPosition = index;
            returnResult.TotalRecords    = result.TotalRecords;
            returnResult.keywords        = result.keywords;
            decimal pages = Decimal.Ceiling(Convert.ToDecimal(returnResult.TotalRecords) / 10);

            int from = (index * 10) - 10;
            int to   = (index * 10);

            if (to > result.TotalRecords)
            {
                to = result.TotalRecords;
            }
            if (from > to)
            {
                from = (Convert.ToInt32(pages) - 1) * 10;
                returnResult.CurrentPosition = Convert.ToInt32(pages);
            }
            Content[] returnContents = new Content[to - from];
            int       current        = 0;

            for (int i = from; i < to; i++)
            {
                returnContents[current] = result.Contents[i];
                current++;
            }
            returnResult.Contents = returnContents;


            if (command == "next")
            {
                if (returnResult.TotalRecords > 0)
                {
                    if (pages >= start + 10)
                    {
                        returnResult.StartPosition += 10;
                    }
                }
            }

            return(PartialView("Search", returnResult));
        }
Esempio n. 14
0
        public static object Get(string key)
        {
            object obj = WebCache.Get(key);

            if (obj == null)
            {
                obj = Provider.Get(key);
            }
            return(obj);
        }
Esempio n. 15
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. 16
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. 17
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. 18
0
        public ActionResult SearchByCategory(string category)
        {
            string         text         = Session["text"].ToString();
            SearchResponse response     = WebCache.Get("searchResponse" + text);
            SearchResponse returnResult = new SearchResponse();

            returnResult.keywords = new List <string>();
            Dictionary <string, Content> contents = new Dictionary <string, Models.Content>();
            int totalRecords = 0;

            foreach (Content c in response.Contents)
            {
                string desc = c.Desc;

                IEnumerable <Record> contain = CategoryMappings.Records.Where(x => desc.Contains(x.Keyword));
                foreach (Record r in contain)
                {
                    if (r.Category == category)
                    {
                        Content copyContent = new Content();
                        if (contents.ContainsKey(c.Id))
                        {
                            copyContent      = contents[c.Id];
                            copyContent.Desc = copyContent.Desc.Replace(r.Keyword, "<span class='post-tag'>" + r.Keyword + "</span>");
                        }
                        else
                        {
                            contents.Add(c.Id, copyContent);
                            totalRecords            += 1;
                            copyContent.Desc         = desc.Replace(r.Keyword, "<span class='post-tag'>" + r.Keyword + "</span>");
                            copyContent.DonorName    = c.DonorName;
                            copyContent.Id           = c.Id;
                            copyContent.ImagePath    = c.ImagePath;
                            copyContent.LocationArea = c.LocationArea;
                            copyContent.Title        = c.Title;
                            copyContent.ViewCount    = c.ViewCount;
                        }

                        if (!returnResult.keywords.Contains(r.Keyword))
                        {
                            returnResult.keywords.Add(r.Keyword);
                        }
                    }
                }
            }
            returnResult.StartPosition        = 1;
            returnResult.CurrentPosition      = 1;
            returnResult.TotalRecords         = totalRecords;
            returnResult.Statistics           = response.Statistics;
            returnResult.Contents             = contents.Values.ToArray();
            Session["searchResponseCategory"] = returnResult;
            Session["category"]       = true;
            Session["categoryString"] = category;
            return(PartialView("Search", returnResult));
        }
Esempio n. 19
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. 20
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. 21
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. 22
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));
        }
        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);
        }
        // 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 List <Category> Get()
        {
            var cache = WebCache.Get("CategoryList");

            if (cache == null)
            {
                cache = _categoryService.GetAllCategories();
                WebCache.Set("CategoryList", cache, 60, true);
            }

            return(cache);
        }
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);
        }
Esempio n. 28
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. 29
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);
        }
        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);
        }