public MongoCacheItem(Guid id, Uri url, Response response) { Id = id; Url = url; CachedOn = DateTime.UtcNow; Response = response; }
/// <summary> /// Caches the response for the specified key. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> public void Put(UrlRequest request, Response response) { MemoryCache cache = MemoryCache.Default; var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.Add(_expiration) // SlidingExpiration = _expiration }; cache.Add(request.CacheKey.ToString(), response, policy); }
public void Put(UrlRequest request, Response value) { string valueString; using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof (Response)); serializer.WriteObject(ms, value); ms.Position = 0; valueString = Encoding.Default.GetString(ms.ToArray()); } using (DbConnection connection = _factory.CreateConnection()) { connection.ConnectionString = _connectionString; connection.Open(); DbCommand cmd = connection.CreateCommand(); cmd.CommandText = "insert into EmbedlyCache ([Key], [Url], [CachedOn], [Value]) values (@key, @url, @cachedOn, @value)"; DbParameter pKey = cmd.CreateParameter(); pKey.DbType = DbType.Guid; pKey.Direction = ParameterDirection.Input; pKey.ParameterName = "key"; pKey.Value = request.CacheKey; DbParameter pUrl = cmd.CreateParameter(); pUrl.DbType = DbType.AnsiString; pUrl.Direction = ParameterDirection.Input; pUrl.ParameterName = "url"; pUrl.Value = request.Url.AbsoluteUri; DbParameter pCachedOn = cmd.CreateParameter(); pCachedOn.DbType = DbType.DateTime; pCachedOn.Direction = ParameterDirection.Input; pCachedOn.ParameterName = "cachedOn"; pCachedOn.Value = DateTime.UtcNow; DbParameter pValue = cmd.CreateParameter(); pValue.DbType = DbType.String; pValue.Direction = ParameterDirection.Input; pValue.ParameterName = "value"; pValue.Value = valueString; cmd.Parameters.Add(pKey); cmd.Parameters.Add(pUrl); cmd.Parameters.Add(pCachedOn); cmd.Parameters.Add(pValue); cmd.ExecuteNonQuery(); } }
public void Put(UrlRequest request, Response response) { // no-op }
/// <summary> /// Initializes a new instance of the <see cref="Result"/> class. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> public Result(UrlRequest request, Response response) { Request = request; Response = response; }
public void Put(UrlRequest request, Response response) { var cacheItem = new MongoCacheItem(request.CacheKey, request.Url, response); _collection.Insert(cacheItem, SafeMode.False); }