简体   繁体   中英

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM