public async Task <ActionResult> CacheCreate()
        {
            await _enrichedMemoryCache.GetOrAdd("TestValue1", () => Task.FromResult(1), new Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions {
            },
                                                new Dictionary <string, string> {
                { "TagKey1", "TagValue" }
            });

            await _enrichedMemoryCache.GetOrAdd("TestValue2", () => Task.FromResult(2), new Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions {
            },
                                                new Dictionary <string, string> {
                { "TagKey1", "TagValue" }
            });

            var a = _enrichedMemoryCache.Get <object>("TestValue2");

            var b = _enrichedMemoryCache.Get <object>("bla");

            return(Ok(5));
        }
Ejemplo n.º 2
0
        public async Task <TEntity> GetAsync(ObjectId id)
        {
            var cachedEntity = await _memoryCache.GetOrAdd(GetCacheKey(id), () => _dal.GetAsync(id), CacheOptions,
                                                           new Dictionary <string, string> {
                { CacheKey, id.ToString() }
            }).ConfigureAwait(false);

            if (cachedEntity == null)
            {
                return(await _dal.GetAsync(id).ConfigureAwait(false));
            }

            return(cachedEntity);
        }