public async virtual Task <bool> PathExistsAsync(string path)
        {
            path = NormalizePath(path);
            var cacheKey = CacheKey.With(GetType(), "PathExistsAsync", path);

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(ContentBlobCacheRegion.CreateChangeToken());

                // If requested path is a directory we should always return true because Azure blob storage does not support checking if directories exist
                var result = string.IsNullOrEmpty(Path.GetExtension(path));
                if (!result)
                {
                    var url = GetAbsoluteUrl(path);
                    try
                    {
                        result = await(await _cloudBlobClient.GetBlobReferenceFromServerAsync(new Uri(url))).ExistsAsync();
                    }
                    catch (Exception)
                    {
                        //Azure blob storage client does not provide method to check blob url exist without throwing exception
                    }
                }
                return result;
            }));
        }
示例#2
0
        /// <summary>
        /// Check that blob or folder with passed path exist
        /// </summary>
        /// <param name="path">relative path /folder/blob.md</param>
        /// <returns></returns>
        public virtual bool PathExists(string path)
        {
            var cacheKey = CacheKey.With(GetType(), "PathExists", path);

            return(_memoryCache.GetOrCreateExclusive(cacheKey, (cacheEntry) =>
            {
                path = NormalizePath(path);
                cacheEntry.AddExpirationToken(Watch(path));
                cacheEntry.AddExpirationToken(ContentBlobCacheRegion.CreateChangeToken());
                var retVal = Directory.Exists(path);
                if (!retVal)
                {
                    retVal = File.Exists(path);
                }
                return retVal;
            }));
        }
        public ActionResult ResetCache()
        {
            //TODO: Replace to some other (maybe with using reflection)
            ThemeEngineCacheRegion.ExpireRegion();
            CartCacheRegion.ExpireRegion();
            CatalogCacheRegion.ExpireRegion();
            ContentBlobCacheRegion.ExpireRegion();
            CustomerCacheRegion.ExpireRegion();
            MarketingCacheRegion.ExpireRegion();
            PricingCacheRegion.ExpireRegion();
            QuoteCacheRegion.ExpireRegion();
            RecommendationsCacheRegion.ExpireRegion();
            StaticContentCacheRegion.ExpireRegion();
            StoreCacheRegion.ExpireRegion();
            TaxCacheRegion.ExpireRegion();
            SubscriptionCacheRegion.ExpireRegion();
            SecurityCacheRegion.ExpireRegion();

            return(StoreFrontRedirect("~/"));
        }
示例#4
0
        public async virtual Task <bool> PathExistsAsync(string path)
        {
            path = NormalizePath(path);
            var cacheKey = CacheKey.With(GetType(), "PathExistsAsync", path);

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(ContentBlobCacheRegion.CreateChangeToken());

                var isDirectory = string.IsNullOrEmpty(Path.GetExtension(path));
                var result = false;

                if (isDirectory)
                {
                    //There is only one way to check if the blob directory exists is to request its contents.
                    BlobContinuationToken token = null;
                    var operationContext = new OperationContext();
                    var directory = GetCloudBlobDirectory(path);
                    var resultSegment = await directory.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, 1, token, _options.BlobRequestOptions, operationContext);
                    result = resultSegment.Results.Any();
                }
                else
                {
                    try
                    {
                        var url = GetAbsoluteUrl(path);
                        result = await(await _cloudBlobClient.GetBlobReferenceFromServerAsync(new Uri(url))).ExistsAsync();
                    }
                    catch (Exception)
                    {
                        //Azure blob storage client does not provide method to check blob url exist without throwing exception
                    }
                }

                return result;
            }));
        }