Reputation: 444
I'd like to properly implement a way to resize images and cache it. Atm i have 2 ways to implement this:
1 Resize on the fly: - Create an url which contains the location of the controller, a width and a height - The controller will create the image if no cached version exist - The controller will serve the cached version
2 Resize first, serve later: - Create an image if no cache version exist and return an url to serve the cached image (using a custom htmlhelper?) - The url will call a controller. The controller will only serve the given cached image
What way would you use to implement image resizing with caching? One of the above versions or a different approach?
I like the 'resize first, serve later' approach the most. Because you wont have to use a width and height in the url. But the pro of 'Resize on the fly' is you have all image handling code at one place
Upvotes: 0
Views: 817
Reputation: 317
I agree with the resize first. In fact, if you cache the image, you will have to recompute when the cache expires. What happens if you replace the image? You will have to handle cache invalidation which can be tricky. Finally, you can still benefit the cache using OutputCache attribute. The only drawback i can see is that you need more space on your disk as you will store both the original and the resized image.
Here is a full article on how to resize images: http://www.codeproject.com/Articles/191424/Resizing-an-Image-On-The-Fly-using-NET
Hope this helps
Upvotes: 1
Reputation: 7705
I'd go with the resize first, serve later approach, particularly if your site makes use of a CDN for caching. Have you seen Image Resizer for MVC? I'm looking into using this for precisely this issue.
Upvotes: 0