public void StoreTwite_ShouldOverwriteExistingValue() { _inMemoryCache.Store(Key, Result1, _cacheTimeSpan); _inMemoryCache.Store(Key, Result2, _cacheTimeSpan); var result = _inMemoryCache.Get <string>(Key); result.ShouldBe(Result2); }
public static async Task <Result <TResult> > GetCachedResult <TResult>(this IInMemoryCache memoryCache, string key, TimeSpan validFor, Func <Task <Result <TResult> > > value) where TResult : class { var cachedResult = memoryCache.Get <TResult>(key); if (cachedResult != null) { return(Success(cachedResult)); } var result = await value(); if (result.IsSuccess && result.Value != null) { memoryCache.Store(key, result.Value, validFor); } return(result); }