Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net 4 Memory Cache class and user Session

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?

like image 272
Jason Avatar asked Dec 22 '22 04:12

Jason


1 Answers

Is MemoryCache equivalent to storing an object/value in for a user in Session Cache

No, it is not equivalent. The ASP.NET Session object is per user key/value storage, whereas MemoryCache is an application level key/value storage (values are shared among all users).

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

In ASP.NET MVC there are usually no web page events but you can access values stored in MemoryCache everywhere within the application.

Basically, in an ASP.NET application, the new MemoryCache object is just a wrapper for the old HttpContext.Cache object (it stores values in the old Cache object).

like image 82
Darin Dimitrov Avatar answered Jan 11 '23 10:01

Darin Dimitrov