Esempio n. 1
0
        private async Task <CacheResult> ProcessAsync(IAsyncResponsePlan e)
        {
            //Verify web.config exists in the cache folder.
            writer.CheckWebConfigEvery5();

            //Cache the data to disk and return a path.
            CacheResult r = await asyncCache.GetCachedFile(e.RequestCachingKey, e.EstimatedFileExtension, async delegate(Stream outStream){
                await e.CreateAndWriteResultAsync(outStream, e);
            }, CacheAccessTimeout, AsyncWrites);


            //Fail
            if (r.Result == CacheQueryResult.Failed)
            {
                GlobalPerf.Singleton.IncrementCounter("diskcache_timeout");
                throw new ImageResizer.ImageProcessingException("Failed to acquire a lock on file \"" + r.PhysicalPath + "\" within " + CacheAccessTimeout + "ms. Caching failed.");
            }

            if (r.Result == CacheQueryResult.Hit && cleaner != null)
            {
                cleaner.UsedFile(r.RelativePath, r.PhysicalPath);
            }

            GlobalPerf.Singleton.IncrementCounter((r.Result == CacheQueryResult.Hit) ? "diskcache_hit" : "diskcache_miss");

            return(r);
        }
Esempio n. 2
0
        public CacheResult Process(IResponseArgs e)
        {
            //Query for the modified date of the source file. If the source file changes on us during the write,
            //we (may) end up saving the newer version in the cache properly, but with an older modified date.
            //This will not cause any actual problems from a behavioral standpoint - the next request for the
            //image will cause the file to be overwritten and the modified date updated.
            DateTime modDate = e.HasModifiedDate ? e.GetModifiedDateUTC() : DateTime.MinValue;

            //Verify web.config exists in the cache folder.
            writer.CheckWebConfigEvery5();

            //Cache the data to disk and return a path.
            CacheResult r = cache.GetCachedFile(e.RequestKey, e.SuggestedExtension, e.ResizeImageToStream, modDate, CacheAccessTimeout, AsyncWrites);

            //Fail
            if (r.Result == CacheQueryResult.Failed)
            {
                throw new ImageResizer.ImageProcessingException("Failed to acquire a lock on file \"" + r.PhysicalPath + "\" within " + CacheAccessTimeout + "ms. Caching failed.");
            }

            if (r.Result == CacheQueryResult.Hit && cleaner != null)
            {
                cleaner.UsedFile(r.RelativePath, r.PhysicalPath);
            }

            return(r);
        }