2012-02-27 44 views
1

对于我的MVC项目(Image Server Application),我无法使用imageresizer进行缓存。我可以使用相似图片和图像源可以是任一文件系统/数据库(依赖injeciton):MVC3中的DiskCache插件imageresizer

本地主机/图像/ 123.jpg宽度= 500
本地主机/图像/ 123宽度= 500

我有路线的MVC 3项目像

 routes.RouteExistingFiles = true; 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     routes.IgnoreRoute("favicon.ico"); 

     routes.MapRoute(
      "ImagesWithExtension", // Route name 
      "images/{imageName}.{extension}/", // URL with parameters 
      new { controller = "Home", action = "ViewImageWithExtension", imageName = "", extension = "", id = UrlParameter.Optional } // Parameter defaults 
     ); 

     routes.MapRoute(
      "Images", // Route name 
      "images/{imageName}/", // URL with parameters 
      new { controller = "Home", action = "ViewImage", imageName = "", id = UrlParameter.Optional } // Parameter defaults 
     ); 

我有两个控制器来处理图像 公众的ActionResult ViewImageWithExtension(字符串imageName,串扩展){} 公众的ActionResult ViewImage(字符串imageName){}

当URL是像缓存完成:? 本地主机/图像/ 123.jpg宽度= 500和图像源是文件系统
本地主机/图像/ 123宽度= 500缓存不工作图像源是文件系统
本地主机/图像/ 123.jpg宽度= 500缓存不工作时,图像源DB
本地主机/图像/ 123宽度= 500缓存不工作时,图像源DB

我的web配置是这样的:?

<configSections> 
    <section name="resizer" type="ImageResizer.ResizerSection" /> </configSections> 


<resizer> 
    <!-- Unless you (a) use Integrated mode, or (b) map all reqeusts to ASP.NET, 
     you'll need to add .ashx to your image URLs: image.jpg.ashx?width=200&height=20 
     Optional - this is the default setting --> 
    <diagnostics enableFor="AllHosts" /> 
    <pipeline fakeExtensions=".ashx" /> 
    <DiskCache dir="~/MyCachedImages" autoClean="false" hashModifiedDate="true" enabled="true" subfolders="32" cacheAccessTimeout="15000" asyncWrites="true" asyncBufferSize="10485760" /> 
    <cleanupStrategy startupDelay="00:05" minDelay="00:00:20" maxDelay="00:05" optimalWorkSegmentLength="00:00:04" targetItemsPerFolder="400" maximumItemsPerFolder="1000" avoidRemovalIfCreatedWithin="24:00" avoidRemovalIfUsedWithin="4.00:00" prohibitRemovalIfUsedWithin="00:05" prohibitRemovalIfCreatedWithin="00:10" /> 
    <plugins> 
     <add name="DiskCache" /> 
    </plugins> </resizer> 

我做错了什么或Imageresizer不支持这种情况?如果没有任何好的插件使用基于磁盘的映像cahce?

在此先感谢。

回答

3

正如我在其他同时发布此问题的公共论坛中所解释的那样,ImageResizer从头开始支持依赖注入。你试图用更多的依赖注入来包装依赖注入,但是向后。 A)ASP.NET MVC 3 and 4 prevent efficient disk caching, by design。您需要与工作ImageResizer HttpModule,而不是反对它,以获得良好的性能。这意味着使用URL API,而不是由您自己的MVC ActionResults包装的托管API。听我的podcast with Scott Hanselman欲知更多信息。 B)SqlReader,S3Reader,MongoReader,VirtualFolder和AzureReader都支持动态注入,并且可以(只需一点点配置)都使用相同的路径语法。 ImageResizer旨在允许在数据存储之间轻松迁移。

C)您可以使用Config.Current.Pipeline.Rewrite事件来使URL API使用任何您想要的语法。这比MVC路线更灵活(并且更少错误)。 D)如果您想添加另一层依赖注入,请执行IPlugin,然后动态选择适当的数据存储,并使用Install方法对其进行组态。