public abstract class AbstractObjectCacher<T> {
#region IoC
private IObjectCache<T> cache;
public IObjectCache<T> Cache {
set { cache = value; }
get { return cache; }
}
#endregion
public T Get() {
return cache.Get();
}
public void Set(T obj) {
cache.Set(obj);
}
public void Dispose() {
T obj = Get();
if(obj != null) {
Set(default(T));
if(obj is IDisposable) {
((IDisposable)obj).Dispose();
}
obj = default(T);
}
cache.Clear();
}
}
So for instance, the thread store i use for unit testing will look like this:
public class ThreadObjectCache<T> : IObjectCache<T> {
#region IoC
private string key;
public string Key {
set {
key = value;
ThreadStore.Initialise(key);
}
get { return key; }
}
#endregion
public T Get() {
return (T)ThreadStore.Get(key);
}
public void Set(T obj) {
ThreadStore.Set(key, obj);
}
public void Clear() {
ThreadStore.Set(key, null);
}
public void Dispose() {
ThreadStore.Dispose(key);
}
}
And the HttpContext store will look like this:
public class HttpContextCache<T> : IObjectCache<T> {
#region IoC
private string key;
public string Key {
set { key = value; }
get { return key; }
}
#endregion
public T Get() {
return (T)HttpContext.Current.Items[key];
}
public void Set(T obj) {
HttpContext.Current.Items[key] = obj;
}
public void Clear() {
HttpContext.Current.Items[key] = null;
}
public void Dispose() {
HttpContext.Current.Items.Remove(key);
}
}
2 comments:
instyler, hollister, oakley, nfl jerseys, jimmy choo outlet, nike air max, north face outlet, soccer jerseys, louboutin, hollister, celine handbags, ghd hair, baseball bats, soccer shoes, gucci, ray ban, beats by dre, longchamp uk, lululemon, nike air max, ralph lauren, ferragamo shoes, bottega veneta, converse outlet, p90x workout, mcm handbags, nike trainers uk, converse, vans outlet, north face outlet, giuseppe zanotti outlet, hermes belt, reebok outlet, mont blanc pens, hollister clothing, chi flat iron, babyliss, herve leger, mac cosmetics, nike roshe run, valentino shoes, insanity workout, vans, nike huaraches, wedding dresses, iphone cases, timberland boots, new balance shoes, abercrombie and fitch, asics running shoes
I was excited to discover this website
http://www.prokr.net/2016/09/furniture-moving-company-al-madina.html
http://www.prokr.net/2016/09/furniture-moving-company-yanbu.html
Post a Comment