public void Set(string key, NancyContext context, DateTime absoluteExpiration) { SetCache(); if(_cache == null) return; _cache[key] = new SerializableResponse(context.Response, absoluteExpiration); }
public CachedResponse(SerializableResponse response) { ContentType = response.ContentType; Headers = response.Headers; StatusCode = response.StatusCode; OldResponseOutput = response.Contents; Contents = GetContents(this.OldResponseOutput); Expiration = response.Expiration; Headers["X-Nancy-LightningCache-Expiration"] = response.Expiration.ToString(CultureInfo.InvariantCulture); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="context"></param> /// <param name="absoluteExpiration"></param> public void Set(string key, NancyContext context, DateTime absoluteExpiration) { lock (_lock) { var fileName = Hash(key); if (File.Exists(Path.Combine(_cacheDirectory, fileName))) File.Delete(Path.Combine(_cacheDirectory, fileName)); var serializedResponse = new SerializableResponse(context.Response, absoluteExpiration); var json = _javaScriptSerializer.Serialize(serializedResponse); File.WriteAllText(Path.Combine(_cacheDirectory, fileName), json); DeleteExpiredCacheFiles(); FileKeyExpirationRecord[fileName] = absoluteExpiration; } }
public void Set(string key, NancyContext context, DateTime absoluteExpiration) { Memory[key] = new SerializableResponse(context.Response, absoluteExpiration); }