asp.net mvc2 缩略图缓存
我正在 asp.net mvc 2 中制作 Web 应用程序,这是某种相册。我必须动态制作和显示缩略图(不保存在磁盘上),并且我想将这些缩略图保留在缓存中。是否可以在 mvc2 中实现以及如何实现?或者将缩略图保存到磁盘可能更好(尽管我想避免这种情况,因为应该有动态设置缩略图大小的选项)
谢谢,
岛
I'm making web application in asp.net mvc 2 which is some kind of photogallery. I will have to dynamically make and display thumbnails (not save on disk) and I would like to keep these thumbnails in cache. Is it possible to do it in mvc2 and how? Or is it maybe better to save thumbnails to disk (although I would like to avoid this because there should be option for dynamically set size of thumbnails)
Thanks,
Ile
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只需要一些固定大小(3 或 4),那么最好生成文件并将它们保存在磁盘上。
如果您确实需要动态大小(作为参数),那么最简单的解决方案是使用 ASP .Net 输出缓存。
OutputCacheAttribute
(特殊操作过滤器)可将其集成到 ASP .Net MVC 项目中。If you just need some fixed sizes (3 or 4) then it would be better to generate files and save them on the disk.
If you really need dynamic size (as parameter) then the easiest solution will be using ASP .Net Output Cache. There is
OutputCacheAttribute
(special action filter) for integrating it into ASP .Net MVC projects.图像等静态资源通常由浏览器缓存,因此这可能是您可以使用的第一级缓存。由于您正在生成动态缩略图,因此您仍然可以设置适当的缓存标头,以便用户缓存这些缩略图。如果您想要为所有用户共享缓存,那么您需要将其存储在服务器上。如果您不想将缩略图保存在磁盘上,您始终可以使用内置的缓存对象,但这会进入内存,您可能很快就会开始耗尽内存。当发生这种情况时,您可以使用
memcached
等提供程序卸载缓存,或者只是将它们保存在磁盘上。Well static resources such as images are normally cached by the browser so that's probably the first level of cache you could be using. Because you are generating dynamic thumbnails you could still set proper caching headers so that those thumbnails are cached by the user. If you want a shared cache for all your users then you will need to store it on the server. If you don't want to save the thumbnails on disk you could always use the built-in Cache object but that's going into memory and you might quickly start running out of memory. And when this happens you could off-load your cache using providers like
memcached
or simply save them on disk.