public void SetCallsSerializerAndCache() { _distributedResponseCache.Set(Key, _deserializedValue, default(TimeSpan)); A.CallTo(() => _fakeCacheSerializer.Serialize(_deserializedValue)) .MustHaveHappenedOnceExactly(); A.CallTo(() => _fakeDistributedCache.Set(Key, _serializedValue, A <DistributedCacheEntryOptions> ._)) .MustHaveHappenedOnceExactly(); }
/// <summary> /// 直接调用方法,并把结果加入缓存 /// </summary> /// <param name="context"></param> /// <param name="next"></param> /// <param name="key">缓存key</param> /// <param name="type">缓存值类型</param> /// <returns></returns> public async Task GetResultAndSetCache(IRocketMethodInvocation invocation, string cacheKey, long expiration) { await invocation.ProceedAsync().ContinueWith(task => { if (invocation.ReturnValue != null) { _cache.SetAsync(cacheKey, _serializer.Serialize(invocation.ReturnValue), new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(expiration))); } }); }
public OrchestrationTests() { // Setup Distributed Cache _fakeDistributedCache = A.Fake <IDistributedCache>(); A.CallTo(() => _fakeDistributedCache.Get(Key)).Returns(_serializedValue); A.CallTo(() => _fakeDistributedCache.GetAsync(Key, default(CancellationToken))).Returns(_serializedValue); // Setup Serializer _fakeCacheSerializer = A.Fake <IDistributedCacheSerializer>(); A.CallTo(() => _fakeCacheSerializer.Serialize(_deserializedValue)).Returns(_serializedValue); A.CallTo(() => _fakeCacheSerializer.Deserialize(_serializedValue)).Returns(_deserializedValue); // Setup DistributedResponseCache _distributedResponseCache = new DistributedResponseCache(_fakeDistributedCache, _fakeCacheSerializer); }
public void Set(string key, IResponseCacheEntry entry, TimeSpan validFor) { var serializedValue = _serializer.Serialize(entry); _distributedCache.Set(key, serializedValue); }