.NET Application Cache vs Database Cache
Im building a image gallery which reads file from disk, create thum开发者_如何学Pythonbnails on the fly and present them to the user. This works good, except the processing takes a bit time.
I then decided to cache the processed images using the ASP .NET Application Cache. When a image is processed I add the byte[] stream to the cache. As far as I know this is beeing saved into the system memory. And this is working perfect, the loading of the page is much faster.
My question is if there are thousands of images which gets cached in the Application Cache, will that affect the server performance in any way?
Are there other, better ways to do this image caching?
By default Application Cache stores data on server memory; depending on your website navigation pattern, maybe you don't get too many cache hits.
You could to preprocess all images to generate its thumbnails at once and store it with your original image. This way you don't need to deal with that cache layer and, probably, won't take too much more disk space.
It depends how many images you have, and memory on your server. My preference would be to write the thumbnails to disk and not put them an in-memory cache. You will presumably be running the site from a raid-enabled disk so read speeds will be quick, alongside IIS being optimised for disk reads.
Yes, you can definitely impact web server performance by putting too much stuff in cache.
One reason Cache was added to ASP.Net was to add its functionality of clearing the oldest/least-used items from the cache if server memory starts getting maxed out. If you cache the items in the Application object, there will be no clean-up, and the server can ultimately run out of memory. Using the Cache object will help you avoid that.
The Cache object also allows you to set various rules about expiration. So, for example, you might put a time limit on how long those images are retained in cache.
精彩评论