示例#1
0
        public IWorkflow GetPublicationWorkflow(Item item)
        {
            string cacheKey = $"{getSiteRoot(item).Publication_Code}-PublicationWorkflow";

            IWorkflow workflowFromCache = _cacheProvider.GetFromCache <IWorkflow>(cacheKey);

            if (workflowFromCache == null)
            {
                var workflow = _service.GetItem <IWorkflow>(getSiteRoot(item).Workflow);
                _cacheProvider.AddToCache(cacheKey, workflow);
                return(workflow);
            }

            return(workflowFromCache);
        }
        public DateTime GetLocalDateTime(string microSiteId)
        {
            var citydatetime = DateTime.Now;

            if (microSiteId == "london" || microSiteId == "international")
            {
                return(DateTime.Now);
            }

            const string timeZonesCacheKey = "TimeZones";

            var timeZoneList = _cacheProvider.GetFromCache <Dictionary <string, TimeZoneInformation> >(timeZonesCacheKey);

            if (timeZoneList == null)
            {
                //read and populate time zones from the registry
                var mZones = TimeZoneInformation.EnumZones();
                Array.Sort(mZones, new TimeZoneComparer());

                timeZoneList = new Dictionary <string, TimeZoneInformation>();

                foreach (var tzone in mZones)
                {
                    if (!timeZoneList.ContainsKey(tzone.Name))
                    {
                        timeZoneList.Add(tzone.Name, tzone);
                    }
                }

                //cache this for 5 mins
                if (timeZoneList.Count > 0)
                {
                    _cacheProvider.AddToCache(timeZonesCacheKey, timeZoneList, DateTime.Now.AddDays(1));
                }
            }

            var tzsn = GetCityTimeZoneStandardName(microSiteId);

            if (!timeZoneList.ContainsKey(tzsn))
            {
                return(citydatetime);
            }

            var destinationTimeZoneInfo = timeZoneList[tzsn];
            var local = DateTime.Now;
            var utc   = local.ToUniversalTime();

            if (destinationTimeZoneInfo == null)
            {
                return(citydatetime);
            }

            var destinationTime = destinationTimeZoneInfo.FromUniversalTime(utc);

            citydatetime = destinationTime;

            return(citydatetime);
        }
示例#3
0
        private void GetLanguageList(List <Language> cachedLangs, string languageCachKey)
        {
            var langs = _translationService.GetAllLanguages();

            cachedLangs.AddRange(langs);

            //cache this for 5 mins
            if (cachedLangs.Count > 0)
            {
                _cacheProvider.AddToCache(languageCachKey, cachedLangs, DateTime.Now.AddMinutes(5));
            }
        }
        public override List <FlagConfigurationViewModel> GetFlagConfiguration()
        {
            var exists = _cacheProvider.KeyExists(Constants.CacheKeys.FlagConfig);

            if (exists)
            {
                var list = _cacheProvider.GetFromCache <List <FlagConfigurationViewModel> >(Constants.CacheKeys.FlagConfig);
                return(list);
            }
            else
            {
                var list = base.GetFlagConfiguration();
                _cacheProvider.AddToCache(Constants.CacheKeys.FlagConfig, list);
                return(list);
            }
        }
        public Product[] GetProductList(ICacheProvider cacheProvider)
        {
            var tourList = cacheProvider.GetFromCache <Product[]>(ProductListCacheName);

            if (tourList != null)
            {
                return(tourList);
            }

            var productListRequest = new ProductListRequest
            {
                AgentCode = _agentCode,
                AgentUID  = _agentUiId,
                ApiKey    = _apiKey
            };

            var tourlist = _clientApi.ProductList(productListRequest);

            cacheProvider.AddToCache(ProductListCacheName, tourlist.Products, DateTime.Now.AddMinutes(20));

            return(tourlist.Products);
        }
 public void Add(string key, object o, DateTimeOffset expiration, string dependsOnKey = null)
 {
     // Ignore expiration
     _cacheProvider.AddToCache(key, o);
 }
示例#7
0
        public void AddToCache <T>(string key, T value) where T : class
        {
            var newKey = GenerateCacheKey(key);

            Provider.AddToCache(newKey, value);
        }