From fa08bc8b8dc786f7c19e30f78f5b30416c6cf1a2 Mon Sep 17 00:00:00 2001 From: Rick Anderson Date: Wed, 14 Aug 2019 19:28:35 -0400 Subject: [PATCH] Update memory.md (#13786) * Update memory.md * Update memory.md * Update memory.md * Update memory.md --- aspnetcore/performance/caching/memory.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aspnetcore/performance/caching/memory.md b/aspnetcore/performance/caching/memory.md index d7a9e91329..49bda03d8b 100644 --- a/aspnetcore/performance/caching/memory.md +++ b/aspnetcore/performance/caching/memory.md @@ -4,7 +4,7 @@ author: rick-anderson description: Learn how to cache data in memory in ASP.NET Core. ms.author: riande ms.custom: mvc -ms.date: 04/11/2019 +ms.date: 8/11/2019 uid: performance/caching/memory --- # Cache in-memory in ASP.NET Core @@ -51,7 +51,11 @@ Use `System.Runtime.Caching`/`MemoryCache` as a compatibility bridge when portin ## Using IMemoryCache -In-memory caching is a *service* that's referenced from your app using [Dependency Injection](../../fundamentals/dependency-injection.md). Call `AddMemoryCache` in `ConfigureServices`: +> [!WARNING] +> Using a *shared* memory cache from [Dependency Injection](xref:fundamentals/dependency-injection) and calling `SetSize`, `Size`, or `SizeLimit` to limit cache size can cause the app to fail. When a size limit is set on a cache, all entries must specify a size when being added. This can lead to issues since developers may not have full control on what uses the shared cache. For example, Entity Framework Core uses the shared cache and does not specify a size. If an app sets a cache size limit and uses EF Core, the app throws an `InvalidOperationException`. +> When using `SetSize`, `Size`, or `SizeLimit` to limit cache, create a cache singleton for caching. For more information and an example, see [Use SetSize, Size, and SizeLimit to limit cache size](#use-setsize-size-and-sizelimit-to-limit-cache-size). + +In-memory caching is a *service* that's referenced from your app using [Dependency Injection](xref:fundamentals/dependency-injection). Call `AddMemoryCache` in `ConfigureServices`: [!code-csharp[](memory/sample/WebCache/Startup.cs?highlight=9)]