Пример #1
0
        public async Task ProcessAsync(HttpContext context, IAsyncResponsePlan e)
        {
            if (!this.AsyncModuleMode)
            {
                throw new InvalidOperationException("DiskCache cannot be used in asynchronous mode if AsyncModuleMode=false");
            }
            CacheResult r = await ProcessAsync(e);

            context.Items["FinalCachedFile"] = r.PhysicalPath;

            if (r.Data == null)
            {
                //Calculate the virtual path
                string virtualPath = VirtualCacheDir.TrimEnd('/') + '/' + r.RelativePath.Replace('\\', '/').TrimStart('/');

                //Rewrite to cached, resized image.
                context.RewritePath(virtualPath, false);
            }
            else
            {
                //Remap the response args writer to use the existing stream.
                e.CreateAndWriteResultAsync = delegate(Stream s, IAsyncResponsePlan plan)
                {
                    return(((MemoryStream)r.Data).CopyToAsync(s));
                };
                context.RemapHandler(new NoCacheAsyncHandler(e));
            }
        }
Пример #2
0
        public void Process(HttpContext context, IResponseArgs e)
        {
            if (this.AsyncModuleMode)
            {
                throw new InvalidOperationException("DiskCache cannot be used in synchronous mode if AsyncModuleMode=true");
            }
            CacheResult r = Process(e);

            context.Items["FinalCachedFile"] = r.PhysicalPath;
            if (r.Data == null)
            {
                //Calculate the virtual path
                string virtualPath = VirtualCacheDir.TrimEnd('/') + '/' + r.RelativePath.Replace('\\', '/').TrimStart('/');

                //Rewrite to cached, resized image.
                context.RewritePath(virtualPath, false);
            }
            else
            {
                //Remap the response args writer to use the existing stream.
                ((ResponseArgs)e).ResizeImageToStream = delegate(Stream s) {
                    ((MemoryStream)r.Data).WriteTo(s);
                };
                context.RemapHandler(new NoCacheHandler(e));
            }
        }
Пример #3
0
        public void Process(HttpContext context, IResponseArgs e)
        {
            CacheResult r = Process(e);

            context.Items["FinalCachedFile"] = r.PhysicalPath;

            if (r.Data == null)
            {
                //Calculate the virtual path
                string virtualPath = VirtualCacheDir.TrimEnd('/') + '/' + r.RelativePath.Replace('\\', '/').TrimStart('/');

                //Rewrite to cached, resized image.
                context.RewritePath(virtualPath, false);
            }
            else
            {
                //Remap the response args writer to use the existing stream.
                ((ResponseArgs)e).ResizeImageToStream = delegate(Stream s) {
                    ((MemoryStream)r.Data).WriteTo(s);
                };
                context.RemapHandler(new NoCacheHandler(e));
            }
        }