Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DbOutputCache.cs 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Linq;
  3. using CacheControl.DataAccess;
  4. using iiie.CacheControl.DBO;
  5. namespace iiie.CacheControl.Business.OutputCache
  6. {
  7. public class DbOutputCache : IOutputCache
  8. {
  9. public override CacheDbo Get(string key)
  10. {
  11. using (var db = new CacheControlEntities())
  12. {
  13. var item = db.T_Cache.FirstOrDefault(x => x.cachekey == key);
  14. if (item == null)
  15. return null;
  16. return new CacheDbo
  17. {
  18. Date = item.date,
  19. ETag = item.etag,
  20. Content = item.content,
  21. ContentType = item.content_type
  22. };
  23. }
  24. }
  25. public override void Remove(string key)
  26. {
  27. using (var db = new CacheControlEntities())
  28. {
  29. var item = db.T_Cache.FirstOrDefault(x => x.cachekey == key);
  30. if (item != null)
  31. {
  32. db.T_Cache.Remove(item);
  33. db.SaveChanges();
  34. }
  35. }
  36. }
  37. public override bool Contains(string key)
  38. {
  39. using (var db = new CacheControlEntities())
  40. {
  41. return db.T_Cache.Any(x => x.cachekey == key);
  42. }
  43. }
  44. public override void Add(string key, CacheDbo o)
  45. {
  46. using (var db = new CacheControlEntities())
  47. {
  48. db.T_Cache.Add(new T_Cache
  49. {
  50. cachekey = key,
  51. etag = o.ETag,
  52. content = o.Content,
  53. date = o.Date,
  54. content_type = o.ContentType
  55. });
  56. db.SaveChanges();
  57. }
  58. }
  59. }
  60. }