首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DiskCache插件在MVC3中的应用

DiskCache插件在MVC3中的应用
EN

Stack Overflow用户
提问于 2012-02-27 10:50:15
回答 1查看 1.3K关注 0票数 1

对于我的MVC项目(),我不能使用imageresizer进行缓存。我可以像这样访问我的映像,图像源可以是文件系统/数据库(依赖注入):

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

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

我有一个MVC 3项目,它的路线如下

代码语言:javascript
复制
        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,字符串扩展) {} public ActionResult ViewImage(string imageName) {}

当URL为:localhost/映像/123.jpg?宽度=500且图像源为FileSystem时,缓存就会完成。

本地主机/图像/123?宽度=500缓存不工作的映像源是文件系统

本地主机/映像/123.jpg?宽度=500缓存不工作,图像源DB

本地主机/图像/123?宽度=500缓存无效,图像源DB

我的web配置如下:

代码语言:javascript
复制
<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?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-03-26 12:42:32

正如我在您同时发布这个问题的其他公共论坛中解释的那样,ImageResizer支持从头到尾的依赖注入。您正在尝试用更多的依赖注入来包装依赖注入,但是是向后的。

A) ASP.NET MVC 3和4通过设计防止了高效的磁盘缓存。。为了获得良好的性能,您需要使用ImageResizer HttpModule,而不是针对它。这意味着使用URL,而不是由您自己的MVC ActionResults包装的托管API。听我的播客获得更多信息。

( B) SqlReader、S3Reader、MongoReader、VirtualFolder和AzureReader都支持动态注入,并且可以(只要配置一点点)都使用相同的路径语法。ImageResizer被设计为允许数据存储之间的轻松迁移。

C)您可以使用Config.Current.Pipeline.Rewrite事件使URL使用您想要的任何语法。这比MVC路线灵活得多(而且buggy更少)。

( D)如果您想要添加另一层依赖项注入,则实现IPlugin,并动态地选择适当的数据存储并从Install方法中配置它。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9463731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档