/// <summary> /// Sets the specified cacheKey, cacheValue and expiration async. /// </summary> /// <returns>The async.</returns> /// <param name="cacheKey">Cache key.</param> /// <param name="cacheValue">Cache value.</param> /// <param name="expiration">Expiration.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public async Task SetAsync <T>(string cacheKey, T cacheValue, TimeSpan expiration) where T : class { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); ArgumentCheck.NotNull(cacheValue, nameof(cacheValue)); ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); await _memcachedClient.StoreAsync(Enyim.Caching.Memcached.StoreMode.Set, this.HandleCacheKey(cacheKey), cacheValue, expiration); }
/// <summary> /// Sets the specified cacheKey, cacheValue and expiration async. /// </summary> /// <returns>The async.</returns> /// <param name="cacheKey">Cache key.</param> /// <param name="cacheValue">Cache value.</param> /// <param name="expiration">Expiration.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public async Task SetAsync <T>(string cacheKey, T cacheValue, TimeSpan expiration) where T : class { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); ArgumentCheck.NotNull(cacheValue, nameof(cacheValue)); ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); if (MaxRdSecond > 0) { var addSec = new Random().Next(1, MaxRdSecond); expiration.Add(new TimeSpan(0, 0, addSec)); } await _memcachedClient.StoreAsync(Enyim.Caching.Memcached.StoreMode.Set, this.HandleCacheKey(cacheKey), cacheValue, expiration); }
/// <summary> /// 设置缓存 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <param name="cacheKey">缓存键</param> /// <param name="cacheValue">缓存值</param> /// <param name="expiry">过期时间</param> public async Task SetAsync <T>(string cacheKey, T cacheValue, TimeSpan expiry) { Check.NotNullOrEmpty(cacheKey, nameof(cacheKey)); Check.NotNull(cacheValue, nameof(cacheValue)); Check.NotNegativeOrZero(expiry, nameof(expiry)); if (MaxRdSecond > 0) { var addSec = new Random().Next(1, MaxRdSecond); expiry.Add(new TimeSpan(0, 0, addSec)); } await _memcachedClient.StoreAsync(StoreMode.Set, this.HandleCacheKey(cacheKey), cacheValue, expiry); }
public async Task <GeoResponse> Query(string q) { var cacheKey = q.Replace(" ", "").ToLower(); var result = await _memcachedClient.GetAsync <GeoResponse>(cacheKey); if (!result.Success) { var queryParts = _geoQueryParser.Parse(q); var sb = new StringBuilder("https://api.geocod.io/v1/geocode?"); foreach (var k in queryParts.Keys) { sb.Append($"{k}={queryParts[k]}&"); } sb.Append("api_key="); sb.Append(Environment.GetEnvironmentVariable("GEOCODIO_API_KEY")); var query = sb.ToString(); var geo = await _geoQueryDispatchService.Query(query).ConfigureAwait(false); await _memcachedClient.StoreAsync(StoreMode.Add, cacheKey, geo, DateTime.Now.AddDays(7)); return(geo); } else { return(result.Value); } }
private async Task <ulong> SendAsync(ILambdaContext context, string cacheReportName, ReducedBandKey bandToMatch) { string key = $"{cacheReportName}_H2H_Band{IncrementCachedH2HCounter(cacheReportName)}"; context.Logger.Log($"{key}"); bool stored = await memcachedClient.StoreAsync(StoreMode.Add, key, bandToMatch, this.expiration); TrackCacheKey(cacheReportName, key); return(1); }
public async Task <IActionResult> Store(string key, [FromQuery] string value) { bool result = await _memcachedClient.StoreAsync(StoreMode.Set, key, value, TimeSpan.Parse("00:00:00")); if (result) { return(StatusCode(StatusCodes.Status201Created)); } else { return(this.ApiErrorResult(_logger)); } }
protected bool Store(StoreMode mode = StoreMode.Set, string key = null, object value = null) { if (key == null) { key = GetUniqueKey("store"); } if (value == null) { value = GetRandomString(); } return(client.StoreAsync(mode, key, value, Expiration.Never).Result); }
protected Task <IOperationResult> Store(StoreMode mode = StoreMode.Set, string key = null, object value = null, ulong cas = Protocol.NO_CAS) { if (key == null) { key = GetUniqueKey("store"); } if (value == null) { value = GetRandomString(); } return(client.StoreAsync(mode, key, value, Expiration.Never, cas)); }
public async void Store_Should_Fail_With_IOException_When_Target_Node_Is_Offline() { IfThrows <IOException>(await client.StoreAsync(StoreMode.Set, GetUniqueKey(), "store", 0, 0)); }
public static Task <IOperationResult> AddAsync(this IMemcachedClient self, string key, object value, ulong cas = Protocol.NO_CAS) { return(self.StoreAsync(StoreMode.Add, key, value, Expiration.Never, cas)); }
public Task <bool> StoreAsync(StoreMode mode, string key, object value, DateTime expiresAt) { return(_memcachedClient.StoreAsync(mode, key, value, expiresAt)); }
public static Task <IOperationResult> ReplaceAsync(this IMemcachedClient self, string key, object value, Expiration expiration, ulong cas = Protocol.NO_CAS) { return(self.StoreAsync(StoreMode.Replace, key, value, expiration, cas)); }
public static Task <IOperationResult> StoreAsync(this IMemcachedClient self, StoreMode mode, string key, object value, Expiration expiration) { return(self.StoreAsync(mode, key, value, expiration, Protocol.NO_CAS)); }
public static IOperationResult Store(this IMemcachedClient self, StoreMode mode, string key, object value, Expiration expiration, ulong cas = Protocol.NO_CAS) { return(self.StoreAsync(mode, key, value, expiration, cas).RunAndUnwrap()); }