开发者

Simple caching mechanism in ASP.NET

I had asked a question on how to implement real time updates in ASP.NET and received a very explanatory and a helpful answer from "jdk" at:

How to implement real time updates in ASP.NET

I understand that memcached or .net caching application block can be used as the caching layer. Currently, I am looking for a very simple mechanism to implement this and do not have the开发者_StackOverflow社区 resources for using memcached or the caching application block.

Can someone suggest a solution?


I am looking for a very simple mechanism to implement this and do not have the resources for using memcached or the caching application block.

You can always store your data into Static fields. This will be shared across all users and will be alive as long as the IIS is not reseted or stopped.


This book has great examples for building out an ASP.NET application using the MVP Design Pattern including a class for handling caching.

ASP.NET 3.5 Social Networking: An Expert Guide to Building Enterprise-Ready Social Networking and Community Applications with ASP.NET 3.5 by Andrew Siemer


static (as Daok has suggested) or as HttpContext.Current.Application["key"] = value;; You wold have to remember the Type every time you "get" it


This will probably cost me some rep, but I've done it and it works: consider using a singleton to cache your data.

Assuming you're looking for a global, read-only cache, and that you don't have a ton of data, you can simply have properties for each cachable element, and wrap the gets in a time check if you need to re-load the data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜