开发者

Implement second level cache in ASP.Net

开发者 https://www.devze.com 2023-03-30 00:07 出处:网络
Is there any way to use caching in ASP.Net except SQL Server second level cache. As it is the first time to work with caching I want any way with an example.开发者_JS百科I have found that NHibernate i

Is there any way to use caching in ASP.Net except SQL Server second level cache. As it is the first time to work with caching I want any way with an example.开发者_JS百科 I have found that NHibernate implements this but we are using .netTiers as an application framework.


The Session cache seems to be the appropriate caching mechanism here. The Session cache is a fault-tolerant cache of objects.

Inserting an object

Session["Username"] = "Matt";

Reading an object

string username = (string)Session["Username"];

Removing an object

Session.Remove("Username");

I say fault-tolerant because if the value with the key you specify doesn't exist in the Session cache, it will not through an exception, it will return null. You need to consider that when implementing your code.

One thing to note, if you are using Sql Server or State Server, the objects you can put in the cache need to be serializable.


Memcached is also a very good way to go, as it is very flexible. It is a windows service that runs on any number of machines and your app can talk to the instances to store and retrieve from the cache. Good Article Here

0

精彩评论

暂无评论...
验证码 换一张
取 消