ilija veselica
ilija veselica

Reputation: 9574

asp.net mvc2 thumbnails cache

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

Upvotes: 1

Views: 423

Answers (2)

oryol
oryol

Reputation: 5248

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.

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1039548

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.

Upvotes: 2

Related Questions