public IVirtualFile GetFileIfCached(string virtualPath, System.Collections.Specialized.NameValueCollection queryString, IVirtualFile original) { if (!"disk".Equals(queryString["scache"], StringComparison.OrdinalIgnoreCase)) { return(null); } if (this.AsyncModuleMode) { throw new InvalidOperationException("SourceDiskCache cannot be used in synchronous mode if AsyncModuleMode=true"); } //Verify web.config exists in the cache folder. writer.CheckWebConfigEvery5(); //Use alternate cache key if provided string key = original is IVirtualFileSourceCacheKey ? ((IVirtualFileSourceCacheKey)original).GetCacheKey(false) : original.VirtualPath; //If cached, serve it. var r = cache.GetCachedFile(key, ".cache", delegate(Stream target) { using (Stream data = original.Open()) { //Very long-running call data.CopyToStream(target); } }, 15 * 1000, true); if (r.Result == CacheQueryResult.Failed) { return(null); } if (r.Result == CacheQueryResult.Hit && cleaner != null) { cleaner.UsedFile(r.RelativePath, r.PhysicalPath); } return(new SourceVirtualFile(original.VirtualPath, delegate(){ return r.Data ?? File.Open(r.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read); })); }
public IVirtualFile GetFileIfCached(string virtualPath, System.Collections.Specialized.NameValueCollection queryString, IVirtualFile original) { if (!"disk".Equals(queryString["scache"], StringComparison.OrdinalIgnoreCase)) { return(null); } //Verify web.config exists in the cache folder. writer.CheckWebConfigEvery5(); //Use alternate cache key if provided string key = original is IVirtualFileSourceCacheKey ? ((IVirtualFileSourceCacheKey)original).GetCacheKey(false) : original.VirtualPath; //If cached, serve it. var r = cache.GetCachedFile(key, ".cache", delegate(Stream target) { using (Stream data = original.Open()) {//Very long-running call StreamExtensions.CopyToStream(data, target); } }, DateTime.MinValue, 15 * 1000, true); if (r.Result == CacheQueryResult.Failed) { throw new ImageResizer.ImageProcessingException("Failed to acquire a lock on file \"" + r.PhysicalPath + "\" within 15 seconds. Source caching failed."); } if (r.Result == CacheQueryResult.Hit && cleaner != null) { cleaner.UsedFile(r.RelativePath, r.PhysicalPath); } return(new SourceVirtualFile(original.VirtualPath, delegate(){ return r.Data ?? File.Open(r.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read); })); }