4

The new class MemoryCache in .Net 4.0 appears to act just like asp.net caching. My questions are:

Is MemoryCache equivalent to storing an object/value in for a user in Session Cache, but not in the code behind of an aspx page.

Can a value stored in MemoryCache, which exists on the server, be accessable to a web page event?

4

2 に答える 2

11

MemoryCache は、ユーザーのオブジェクト/値をセッション キャッシュに格納することと同等ですか?

いいえ、同等ではありません。ASP.NET Session オブジェクトはユーザーごとのキー/値ストレージですが、MemoryCache はアプリケーション レベルのキー/値ストレージです (値はすべてのユーザー間で共有されます)。

サーバー上に存在する MemoryCache に格納された値は、Web ページ イベントにアクセスできますか?

ASP.NET MVC では、通常、Web ページ イベントはありませんが、アプリケーション内のどこからでも MemoryCache に保存されている値にアクセスできます。

基本的に、ASP.NET アプリケーションでは、新しいMemoryCacheオブジェクトは古いオブジェクトの単なるラッパーですHttpContext.Cache(値は古い Cache オブジェクトに格納されます)。

于 2011-12-31T08:43:57.360 に答える