1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Linq;
- using CacheControl.DataAccess;
- using iiie.CacheControl.DBO;
-
- namespace iiie.CacheControl.Business.OutputCache
- {
- public class DbOutputCache : IOutputCache
- {
-
- public override CacheDbo Get(string key)
- {
- using (var db = new CacheControlEntities())
- {
- var item = db.T_Cache.FirstOrDefault(x => x.cachekey == key);
- if (item == null)
- return null;
- return new CacheDbo
- {
- Date = item.date,
- ETag = item.etag,
- Content = item.content,
- ContentType = item.content_type
- };
- }
- }
-
- public override void Remove(string key)
- {
- using (var db = new CacheControlEntities())
- {
- var item = db.T_Cache.FirstOrDefault(x => x.cachekey == key);
- if (item != null)
- {
- db.T_Cache.Remove(item);
- db.SaveChanges();
- }
- }
- }
-
- public override bool Contains(string key)
- {
- using (var db = new CacheControlEntities())
- {
- return db.T_Cache.Any(x => x.cachekey == key);
- }
- }
-
- public override void Add(string key, CacheDbo o)
- {
- using (var db = new CacheControlEntities())
- {
- db.T_Cache.Add(new T_Cache
- {
- cachekey = key,
- etag = o.ETag,
- content = o.Content,
- date = o.Date,
- content_type = o.ContentType
- });
- db.SaveChanges();
- }
- }
- }
- }
|