public (ISyncCacheProvider <TResult>, ISyncPolicy <TResult>) CreateSyncCachePolicy <TCache, TResult>() { var memoryIDistributedCache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions())); ISyncCacheProvider <TResult> memoryIDistributedCacheProvider; if (typeof(TCache) == typeof(string)) { memoryIDistributedCacheProvider = memoryIDistributedCache.AsSyncCacheProvider <string>().WithSerializer <TResult, string>(new JsonSerializer <TResult>(new JsonSerializerSettings())); } else if (typeof(TCache) == typeof(byte[])) { memoryIDistributedCacheProvider = memoryIDistributedCache.AsSyncCacheProvider <byte[]>().WithSerializer(new ByteArraySerializer()).WithSerializer <TResult, string>(new JsonSerializer <TResult>(new JsonSerializerSettings())); } else { throw new ArgumentException($"{nameof(TCache)} must be either {typeof(string).Name} or {typeof(byte).Name}[]", nameof(TCache)); } var policy = Policy.Cache <TResult>(memoryIDistributedCacheProvider, TimeSpan.FromHours(1)); return(memoryIDistributedCacheProvider, policy); }