Posted By

krisdb on 12/03/08


Tagged

c-sharp


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

robe
umang_nine
ddevening
rageit
jalalx


Cache


 / Published in: C#
 

  1. public class Cache
  2. {
  3.  
  4. public static void Add(string name, object data, int hours)
  5. {
  6. HttpContext.Current.Cache.Insert(name, data, null, DateTime.Now.AddHours(hours), TimeSpan.Zero);
  7. }
  8.  
  9. public static object Get(string name)
  10. {
  11. if (HttpContext.Current.Cache[name] != null)
  12. return HttpContext.Current.Cache[name];
  13. else
  14. return null;
  15. }
  16. }
  17.  
  18.  
  19. Clear:
  20. foreach (DictionaryEntry entry in Cache)
  21. Cache.Remove(entry.Key.ToString());

Report this snippet  

You need to login to post a comment.