I wrote my own PageStatePersister
class based on SessionPageStatePersister
which writes the most recent 10 Viewstate
s for a session to a shared disk. I figure this will scale better than keeping Viewstate
in session since all web servers have access to it, they won't have to deal with expiration, and use less memory.
When a user closes the browser it notifies the server and the server deletes those files which have not been accessed for two hours. So far so good but I'm wondering if it will be faster and more efficient to store Viewstate
in an SQL server database instead.
ViewState
file is 30k on average. So which is better in this case: a flatfile system or a database?
It would scale much better to store the ViewState in SQL Server. If you eventually want to increase from 10 most recent to 50 most recent, for example, it would be a relatively trivial increase in DB load. Disk I/O should generally be avoided whenever possible, moreso than DB I/O. Cleanup operations would also work much better, as seeking across a wasteland of abandoned files on disk is probably much heavier than WHERE DateInserted > 20 minutes ago
.