MVC3中的DiskCache插件imageresizer [英] DiskCache plugin imageresizer in MVC3

查看:183
本文介绍了MVC3中的DiskCache插件imageresizer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的MVC项目(图像服务器应用程序),我无法使用imageresizer进行缓存。我可以像这样访问我的图像,图像源可以是FileSystem / Database(Dependency injeciton):

For my MVC project (Image Server Application), I cannot do caching using imageresizer. I can access my images like this and the image source could be either FileSystem/Database (Dependency injeciton) :

localhost / images / 123.jpg?width = 500

localhost / images / 123?width = 500

localhost/images/123.jpg?width=500
localhost/images/123?width=500

我有一个MVC 3项目,其路线如

I have an MVC 3 project with routes like

        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
        );

我有两个控制器来处理图像
public ActionResult ViewImageWithExtension(string imageName,string extension ){}
public ActionResult ViewImage(string imageName){}

I have two controllers to deal with images public ActionResult ViewImageWithExtension(string imageName, string extension) {} public ActionResult ViewImage(string imageName) {}

当URL如下所示进行缓存:
localhost / images / 123 .jpg?width = 500,图像源是FileSystem

localhost / images / 123?width = 500缓存不工作图像源是Filesystem

localhost / images / 123.jpg? width = 500缓存不工作,图像源数据库

localhost / images / 123?width = 500缓存无法正常工作,图像源数据库

The caching is done when the URL is like : localhost/images/123.jpg?width=500 and the image source is FileSystem
localhost/images/123?width=500 Cache not working image source is Filesystem
localhost/images/123.jpg?width=500 Cache not working, image source DB
localhost/images/123?width=500 Cache not working , image source DB

我的网站config是这样的:

My web config is like this:

<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不支持这种情况?如果没有任何好的插件可以使用基于磁盘的图像?

Am I doing something wrong or Imageresizer doesnt support this scenario ? If not any good plugin to use disk based image cahce ?

提前致谢。

推荐答案

正如我在同时发布此问题的其他公共论坛中所解释的那样,ImageResizer从头开始支持依赖注入。您试图通过更多的依赖注入来包装依赖注入,但是向后。

As I explained in the other public forums which you simultaneously posted this question, the ImageResizer supports dependency injection from the ground up. You're trying to wrap dependency injection with more dependency injection, but backwards.

A) ASP.NET MVC 3和4阻止高效磁盘缓存,按设计。您需要使用使用使用ImageResizer HttpModule而不是使用它来获得良好的性能。这意味着使用URL API,而不是您自己的MVC ActionResults包装的Managed API。听我的与Scott Hanselman播客获取更多信息。

A) ASP.NET MVC 3 and 4 prevent efficient disk caching, by design. You need to work with the ImageResizer HttpModule, not against it, to get good performance. That means using the URL API, not the Managed API wrapped by your own MVC ActionResults. Listen to my podcast with Scott Hanselman for more info.

B)SqlReader,S3Reader,MongoReader,VirtualFolder和AzureReader都支持动态注入,并且可以(带有一小部分配置),都使用相同的路径语法。 ImageResizer旨在允许在数据存储之间轻松迁移。

B) SqlReader, S3Reader, MongoReader, VirtualFolder, and AzureReader all support dynamic injection, and can (with a tiny bit of configuration), all use the same path syntax. The ImageResizer is designed to allow easy migration between data stores.

C)您可以使用 Config.Current.Pipeline.Rewrite 使URL API使用您想要的任何语法的事件。这比MVC路由灵活得多(并且没有错误)。

C) You can use the Config.Current.Pipeline.Rewrite event to make the URL API use any syntax you want. This is much more flexible than MVC routes (and less buggy).

D)如果要添加另一层依赖注入,请实现 IPlugin ,并动态选择适当的数据存储并从安装方法进行配置。

D) If you want to add another layer of dependency injection, implement IPlugin, and dynamically pick the appropriate data store and configure it from the Install method.

这篇关于MVC3中的DiskCache插件imageresizer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆