using System; using Nancy; using Nancy.LightningCache.Projection; using Newtonsoft.Json; using Sony.Filtr.DistributedCaching; namespace Sony.Filtr.AdminAPI.Config { public class DistributedCacheStore : Nancy.LightningCache.CacheStore.ICacheStore { private const string Prefix = "LightningCacheStore-1.6"; private readonly DistributedCacheHandler _distributedCacheHandler; public DistributedCacheStore(DistributedCacheHandler distributedCacheHandler) { _distributedCacheHandler = distributedCacheHandler; } public CachedResponse Get(string key) { var responseString = _distributedCacheHandler.Get(Prefix + key) as string; if (responseString != null) { var response = JsonConvert.DeserializeObject(responseString); if (response != null) { return new CachedResponse(response); } } return null; } public void Remove(string key) { _distributedCacheHandler.Remove(Prefix + key); } public void Set(string key, NancyContext context, DateTime absoluteExpiration) { var objectJson = Newtonsoft.Json.JsonConvert.SerializeObject(new SerializableResponse(context.Response, absoluteExpiration)); _distributedCacheHandler.Put(Prefix + key, objectJson, absoluteExpiration); } } }