It is a good idea to use caching for frequently accessed objects to reduce trips to the database or your web services. Here is an example of using the System.Web application cache. You can even use this in dll's outside of your web project, as long as you reference System.Web.
- string cacheName = "objectNameCache";
- int cacheDurationMinutes = 10;
- var cache = System.Web.HttpRuntime.Cache;
- cache.Insert(cacheName, quote, null, DateTime.UtcNow.AddMinutes(cacheDurationMinutes), TimeSpan.Zero);
- // now to access it... First check if null, then simply cast cache to outcoming object.
- if (cache[cacheName] != null)
- {
- quote = (DataTransferObjects.QuoteData)cache[cacheName];
No comments:
Post a Comment