ASP.NET Page.Cache versus Page.Application storage for data synchronization?

旧巷老猫 提交于 2019-12-07 15:20:26

问题


Both Page.Cache and Page.Application can store an application's "global" data, shared among requests and threads.

How should one storage area be chosen over the other considering scenarios of data synchronization in the multi-threaded ASP.NET environment?

Looking for best practice and experienced recommendation.


回答1:


If the data

  • is stable during the life of the application
  • must always be available and must not be purged

better store it in HttpApplicationState.

If the data

  • not necessarily is needed for the life of the application
  • changes frequently
  • can be purged if needed (for example low system memory)
  • can be discarded if seldom used
  • should be invalidated/refreshed under some conditions (dependency rule: time span, date, file timestamp, ...)

then use Cache.

Other important points:

  • Large amounts of data may better be stored in Cache, the server then can purge it if low on memory.
  • Cache is safe for multithreaded operations. Page.Application needs locking.

See also this article on etutorials.org for more details.




回答2:


You typically would store the data in Page.Application Items Collection when you need it within the same request. Page.Cache is typically used in data caching scenarios when you want to use it across multiple requests.



来源:https://stackoverflow.com/questions/2922171/asp-net-page-cache-versus-page-application-storage-for-data-synchronization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!