Here's a hypothetical situation I've been wondering about lately. Suppose I have an interactive page created in ASP.NET and Ajax that I want multiple users to be able to manipulate at the same time. What would be the best way to maintain this page's state? Especially if the page was relatively ephemeral, and did not particularly need to be stored in a database?
As a concrete example, suppose I'm implementing a basic game of checkers. The server needs to maintain the state of the board at all times. The clients need to check the board's status periodically, and need to be able to transmit their changes to the board. When all the players leave, or when the game ends, the board is no longer needed and the server can dispose of it.
I could store everything in a database, retrieving it when the clients ask for a board update, and saving it when the server receives an update. But that seems like a lot of extra overhead.
What about static variables? Are they reliable enough/efficient enough for this job? Is there another storage mechanism I could use? Or is this so far outside the limits of what ASP.NET can do efficiently that I should be looking at an entirely different technology if I ever want to implement this?
Update:
One quick update, to see if I can get another round of answers. After a bit of research, here's what I have so far:
Manu has suggested using MemCached independently to store the data. I like that this solution works even in multi-server environments, but I have noted a few drawbacks:
1) MemCached's site states that it's for read-heavy applications (which this isn't, relative to a traditional web app), and that it's "unreliable." I haven't gotten far enough to determine how important these characteristics are (i.e. are writes slow? Is there a propagation delay?).
2) In an implementation somewhat close to my application (storing session data), the MemCached site uses a database behind the cache, even though the data does not need to be persisted.
3) I have some concerns about how usable MemCached would be in a hosted environment.
Looking at static variables, they do seem to be fast. They aren't thread safe, but that can be accounted for. However, they ARE local to the worker process, so I'm not sure how they work with load balancing or a web garden.
Finally, there is at least one implementation of an ASP.NET-based chat client (VERY similar to this example) which uses a database as a back-end. With proper caching, this may just be "good enough."