コード例 #1
0
        /// <inheritdoc />
        protected override Stream CurrentOpen(PathDefinition definition, string virtualPath)
        {
            bool isValidControlPresentationPath;
            ControlPresentation controlPresentation = this.GetControlPresentation(definition, virtualPath, out isValidControlPresentationPath);

            if (controlPresentation != null && !controlPresentation.Data.IsNullOrEmpty())
            {
                var bytes = RouteHelper.GetContentWithPreamble(controlPresentation.Data);
                return(new MemoryStream(bytes));
            }

            throw new ArgumentException("Could not find resource at " + virtualPath + " in the database.");
        }
コード例 #2
0
        /// <inheritdoc />
        protected override System.Web.Caching.CacheDependency GetCurrentCacheDependency(PathDefinition definition, string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            bool isValidControlPresentationPath;
            ControlPresentation controlPresentation = this.GetControlPresentation(definition, virtualPath, out isValidControlPresentationPath);

            if (!isValidControlPresentationPath)
            {
                // Return null for virtual paths that are not ControlPresentation paths since they do not depend on Control Presentations.
                return(null);
            }

            if (controlPresentation != null)
            {
                return(new ControlPresentationCacheDependency(controlPresentation.Id.ToString()));
            }

            // Change to any ControlPresentation record will invalidate the cache for this virtual path.
            return(new ControlPresentationCacheDependency(typeof(ControlPresentation)));
        }
コード例 #3
0
        /// <inheritdoc />
        protected override bool CurrentExists(PathDefinition definition, string virtualPath)
        {
            var  cacheManager = this.GetCacheManager();
            var  key          = this.GetExistsCacheKey(definition, virtualPath);
            bool?result       = cacheManager[key] as bool?;

            if (result == null)
            {
                lock (this.existsLock)
                {
                    result = cacheManager[key] as bool?;
                    if (result == null)
                    {
                        bool isValidControlPresentationPath;
                        ControlPresentation controlPresentation = this.GetControlPresentation(definition, virtualPath, out isValidControlPresentationPath);
                        result = controlPresentation != null && !controlPresentation.Data.IsNullOrEmpty();

                        cacheManager.Add(key, result, Microsoft.Practices.EnterpriseLibrary.Caching.CacheItemPriority.Normal, null, this.GetControlPresentationsCacheExpirations());
                    }
                }
            }

            return(result.Value);
        }