是否有一种简单的方法可以在ASP.NET中的服务器上的内存中存储一个简单的表,所有用户都可以共享?假设我有一个简单的聊天程序,我只想在内存中保存最后100条记录(这不是一个真正的应用程序,只是一个例子).假设我不希望sql中的整个表专用于只有100条记录的聊天缓冲区.有什么方法可以创建内存数据表并在连接的用户之间共享它?
解决方法
使用
Cache (MSDN)
One instance of this class is created per application domain,and it
remains valid as long as the application domain remains active.
Information about an instance of this class is available through the
Cache property of the HttpContext object or the Cache property of the
Page object.
DataTable yourDataTable = new DataTable(); Cache["yourTable"] = yourDataTable; //to access it DataTable dt = Cache["yourTable"] as DataTable;