简体   繁体   English

数据缓存客户端在asp.net?

[英]Data caching client side in asp.net?

Is it possible to do data caching in client-side in asp.net using c#? 是否可以使用C#在asp.net的客户端进行数据缓存?

I am planning to cache a Dataset . 我打算缓存一个Dataset If so can you please provide a sample? 如果可以,请提供样品吗?

For asp.net & c#.net web application its best to cache these kind of things in server side datacache. 对于asp.net和c#.net Web应用程序,最好将此类内容缓存在服务器端数据缓存中。

The only form of client side cache that I can think of for this is to put the dataset in a session object 我可以想到的唯一形式的客户端缓存是将数据集放入会话对象中

The only real option you have to store large amounts of data client side is by using the ViewState . 您必须在客户端存储大量数据的唯一实际选择是使用ViewState It will only exist on the page you add it to though. 它将仅存在于您添加到的页面上。 So if you are jumping around from page to page it won't really work. 因此,如果您在页面之间跳来跳去,那将是行不通的。 In that case you really should be using Session or Application Cache depending on your scenario. 在那种情况下,您确实应该根据情况使用SessionApplication Cache

So if you are doing something where you are always on the same page and just doing many PostBacks for things like paging or sorting then ViewState will work fine but do realize you will be passing large amounts of data back and forth to the server each time a PostBack is made. 因此,如果您执行的操作始终位于同一页面上,并且仅对分页或排序之类的PostBacks执行了许多PostBacks ,则ViewState可以正常工作,但您会意识到每次每次将大量数据来回传递给服务器时,已完成PostBack

Eg: 例如:

// Set it
ViewState["YourData"] = yourDataSet;

// Get it
DataSet ds = ViewState["YourData"] as DataSet;

Session and the Application Cache are accessed the same way. SessionApplication Cache的访问方式相同。 Just replace ViewState with the word Session or Cache . 只需将ViewState替换为SessionCache

More information regarding the 3 methods can be found on MSDN: 在MSDN上可以找到有关这三种方法的更多信息:

  1. ViewState ViewState
  2. Session 届会
  3. Application Cache 应用缓存

You might want to check out the following links as well: 您可能还想查看以下链接:

Advantages of Cache vs Session 缓存与会话的优势

Session State v ViewState 会话状态v ViewState

http://www.codeproject.com/KB/aspnet/PTCacheSessionViewState.aspx http://www.codeproject.com/KB/aspnet/PTCacheSessionViewState.aspx

Also you can use from external library LocalCaching.dll for .Net Application client side caching 您也可以使用外部库LocalCaching.dll进行.Net应用程序客户端缓存

this codeproject article is a best solution for this library 代码项目文章是此库的最佳解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM