In my previous post, I have mentioned about the improvement and optimizations around ViewState and CacheStorage. In this post, I would like to share one of the exciting features we made in Framework 2007: FileServer Caching.
Since the initial version of the Framework, we have introduced a mechanism to cache data or viewstate to either PageCache or Session. Although PageCache and Session are the most commonly used cache storage point, it has significant drawback. When used effectively to cache small amount of data, it worked great — and it has best performance too since PageCache and Session are both “in-memory” storage.
The problem can be quickly seen as soon as you put a larger amount of data — let’s say a dataset with 1000 rows. This will result in tremendous allocation of RAM and will cause web application to crash or worker process to recycle. Our suggestion with this caching feature is to effectively utilize this feature and avoid caching large amount of data.
Another working solution is by storing the cache to Session, and then set the SessionStorage to SqlServer or StateServer. The session storage capability is provided in ASP.NET class. Although this is working in some scenarios, it doesn’t have good separation between control’s data and session’s data. Furthermore, they are much slower since there are more overhead in accessing the database and state server.
For this reason, we have tried to come up with a better solution (although it’s not a new approach). The better solution is to be able to store the cache to a file server. The file server can be located in the same computer or in a shared folder of network computer.
One good reason to use file server is its easy configuration. In Framework 2007, you can set this option by simply setting the CacheStorage to FileServer and then put the file path setting in the CacheServerConnection property.
The FileServer cache storage is certainly a good option if you don’t want to concern about insufficient memory or slow database access in your web application. Furthermore, since FileServer stores the cache to hard drive, it introduces several advantages such as:
- Hard drive storage has relatively larger spaces than RAM.
- Hard drive can be easily extensible and cheaper.
- Today’s hard drive has very fast performance which is close to RAM speed.
- Easy to maintain and manage.
It is worthy to note that the Framework has automatic cleanup feature. After a specific duration has passed without any interaction to the cache, the cache files will be automatically removed. There is no need to worry with manual cache files cleanup.
All the best,