예제 #1
0
        public bool TryGetValue(string key, out object value)
        {
            var internalKey = _cacheKeyPrefix + key;

            value = _cacheManager.Get(internalKey);
            return(value != null);
        }
        public void AddDependency(string key, string dependencyKey)
        {
            var dependencies = _localCache.Get <IList <string> >(key, ReadStrategy.Immediate);

            if (dependencies == null)
            {
                dependencies = new List <string>();
                _localCache.Insert(key, dependencies, CacheEvictionPolicy.Empty);
            }
            dependencies.Add(dependencyKey);
        }
 public IEnumerable<IStatisticItem> GetStatisticItems(ContentReference rootContentReference)
 {
     var statisticItems = _synchronizedObjectInstanceCache.Get(CacheKey) as IEnumerable<IStatisticItem>;
     if (statisticItems != null)
         return statisticItems;
     statisticItems = _authorStatisticService.GetStatisticItems(rootContentReference);
     _synchronizedObjectInstanceCache.Insert(CacheKey, statisticItems, new CacheEvictionPolicy(new TimeSpan(0, 30, 0), CacheTimeoutType.Absolute));
     return statisticItems;
 }
        public T Get <T>(string key) where T : class
        {
            if (String.IsNullOrWhiteSpace(key))
            {
                return(default(T));
            }

            return(_cacheManager.Get(key) as T);
        }
예제 #5
0
        public bool TryGet <T>(string key, out T value)
        {
            var target = _cache.Get(key);

            if (target != null)
            {
                value = (T)target;
                return(true);
            }

            value = default(T);
            return(false);
        }
예제 #6
0
        public IDictionary <ContentReference, ContentType> ResolveContentTypes(
            IEnumerable <ContentReference> contentLinks)
        {
            var result = new Dictionary <ContentReference, ContentType>();
            var catalogContentLinks =
                contentLinks.Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.Catalog);

            foreach (var catalogContentLink in catalogContentLinks)
            {
                result.Add(catalogContentLink, _catalogContentType);
            }

            var notCachedLinks = new List <ContentReference>();

            foreach (var contentLink in contentLinks)
            {
                var cached = _cache.Get(GetCacheKey(contentLink)) as ContentType;
                if (cached != null)
                {
                    result.Add(contentLink, cached);
                }
                else
                {
                    notCachedLinks.Add(contentLink);
                }
            }

            var nodeContentLinks =
                notCachedLinks.Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.CatalogNode);
            var nodeIds = nodeContentLinks.Select(l => _referenceConverter.GetObjectId(l));

            var entryLinks =
                notCachedLinks.Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.CatalogEntry);
            var entryIds = entryLinks.Select(l => _referenceConverter.GetObjectId(l));

            var ds = LoadMetaClassNames(entryIds, nodeIds);

            foreach (var keyPair in ResolveContentTypes(ds.Tables[0], CatalogContentType.CatalogEntry))
            {
                result.Add(keyPair.Key, keyPair.Value);
                _cache.Insert(GetCacheKey(keyPair.Key), keyPair.Value, _cacheEvictionPolicyFunc(keyPair.Key));
            }

            foreach (var keyPair in ResolveContentTypes(ds.Tables[1], CatalogContentType.CatalogNode))
            {
                result.Add(keyPair.Key, keyPair.Value);
                _cache.Insert(GetCacheKey(keyPair.Key), keyPair.Value, _cacheEvictionPolicyFunc(keyPair.Key));
            }

            return(result);
        }
        public NugetPackage GetCurrentFeedVersion(string packageId)
        {
            // We are calling out to an external service so cache results
            var cacheKey = "NugetFeedParser-Cache-" + packageId;

            if (_cache.Get("NugetFeedParser-Cache-" + packageId) != null)
            {
                var cacheVal = _cache.Get("NugetFeedParser-Cache-" + packageId);
                if (cacheVal.GetType() == typeof(NugetPackage))
                {
                    return((NugetPackage)cacheVal);
                }
                return(null);
            }

            var package = _packageRepository.FindPackage(packageId);

            if (package != null)
            {
                var nugetPackage = new NugetPackage()
                {
                    Id                  = package.Id,
                    PublishedDate       = ((NuGet.DataServicePackage)(package)).LastUpdated.DateTime,
                    Version             = package.Version.Version.ToString(),
                    FullSemanticVersion = package.Version
                };
                _cache.Insert(cacheKey, nugetPackage,
                              new CacheEvictionPolicy(null, null, null, new TimeSpan(1, 0, 0), CacheTimeoutType.Absolute));
                return(nugetPackage);
            }

            //We do actually want to cache the fact we could not find the package on the Episerver Nuget repo, otherwise we'd be hitting the .FindPackage method every time
            _cache.Insert(cacheKey, false,
                          new CacheEvictionPolicy(null, null, null, new TimeSpan(1, 0, 0), CacheTimeoutType.Absolute));

            return(null);
        }
예제 #8
0
        public BlogArticle GetItem(long id)
        {
            var article = _cache.Get <BlogArticle>($"{id}{CacheKeySuffix}", ReadStrategy.Wait);

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

            using (var client = new WebClient())
            {
                var json = client.DownloadString(EktronPath("blogitemhandler", new List <KeyValuePair <string, object> >()
                {
                    new KeyValuePair <string, object>("id", id)
                }));
                article = JsonConvert.DeserializeObject <BlogArticle>(json);
                if (article == null)
                {
                    return(null);
                }
                _cache.Insert($"{id}{CacheKeySuffix}", article, new CacheEvictionPolicy(new TimeSpan(0, 30, 0), CacheTimeoutType.Absolute));
                return(article);
            }
        }
        private List <ResolvedContentType> GetFromCache(IEnumerable <ContentReference> contentLinks, out List <ContentReference> notCached)
        {
            var result = new List <ResolvedContentType>();

            var notCachedLinks = new List <ContentReference>();

            foreach (var contentLink in contentLinks)
            {
                var cached = _cache.Get(GetCacheKey(contentLink)) as ContentType;
                if (cached != null)
                {
                    result.Add(new ResolvedContentType(contentLink, cached));
                }
                else
                {
                    notCachedLinks.Add(contentLink);
                }
            }
            notCached = notCachedLinks;
            return(result);
        }
예제 #10
0
        private void ApplyFocalPointCropping(IUrlEventArgs urlEventArgs)
        {
            var focalPointData = urlResolver.Route(new UrlBuilder(urlEventArgs.VirtualPath)) as IFocalPointData;

            if (focalPointData?.FocalPoint != null)
            {
                var resizeSettings = GetResizeSettingsFromQueryString(urlEventArgs.QueryString);
                if (!ShouldCrop(focalPointData, resizeSettings))
                {
                    return;
                }
                Logger.Information($"Altering resize parameters for {focalPointData.Name} based on focal point.");
                var cacheKey       = GetCacheKeyForResize(focalPointData.ContentLink, resizeSettings);
                var cropParameters = cache.Get(cacheKey) as string;
                if (cropParameters == null)
                {
                    cropParameters = GetCropDimensions(focalPointData, resizeSettings).ToString();
                    cache.Insert(cacheKey, cropParameters, GetEvictionPolicy(focalPointData.ContentLink));
                }
                urlEventArgs.QueryString.Add("crop", cropParameters);
            }
        }
 private IEnumerable <RouteFacetModel> GetCachedFacetNames()
 {
     return(_objectInstanceCache.Get(GetCacheName()) as IEnumerable <RouteFacetModel>);
 }
예제 #12
0
 public object Get(string key) => _defaultCache.Get(key);
예제 #13
0
 public T Get <T>(string key)
 {
     return(CastValue <T>(_cache.Get(key)));
 }
예제 #14
0
 protected virtual TCache GetCachedContent <TCache>(string cacheKey)
     where TCache : class
 {
     return(_synchronizedObjectInstanceCache.Get(cacheKey) as TCache);
 }
예제 #15
0
 public TObj GetObjet <TObj>(string key) where TObj : class
 {
     return(_syncronizedObjectInstanceCache.Get <TObj>(key, ReadStrategy.Immediate));
 }