views:

130

answers:

4

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:

http://stackoverflow.com/questions/2347771/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?

+1  A: 

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.

Daok
Good idea. Is this approach the right way of doing what I plan to achieve?
DotnetDude
It's not a scalable solution but it does exactly what you want in your description.
Daok
Another advantage of this approach is that the 'cache' can be strongly typed. @Daok - it will be cleared every time the app restarts as well. Also, perhaps you should explain what you mean by 'not scalable'
ScottE
@ScottE - Why can't it be strongly typed if I store it in the HttpContext instead of using static
DotnetDude
A: 

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

Robert Williams
My application is non MVC (traditional web forms app). Is this book still helpful for me?
DotnetDude
Yes, this book uses the Model View Presenter (MVP) design pattern rather than the newer ASP.NET MVC design pattern. I would highly recommend because it walks you through the steps of creating a social networking website called "Fisharoo".
Robert Williams
A: 

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

ram
A: 

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.

chris
Interesting. You suggest using a static variable instead of storing it in the Context? Which is better when it comes to performance?
DotnetDude
You really need to figure it out for yourself - how much data are we talking about, what format is it in, how do you use it, and how often does it change? If you decide on this approach, you can store information in static variables, use the asp.net cache, or a combination of the two.
chris