Update memory.md (#5596)

* Update memory.md

Just a typo, I changed the work time by "item" in the `TryGetValue` section.

* Update memory.md

* Additional updates
pull/5597/head
diegotrujillor 2018-03-05 10:06:18 -05:00 committed by Scott Addie
parent ba00c05c8b
commit 9c54d73bee
1 changed files with 4 additions and 4 deletions

View File

@ -41,15 +41,15 @@ Request the `IMemoryCache` instance in the constructor:
`IMemoryCache` requires NuGet package "Microsoft.Extensions.Caching.Memory".
The following code uses [TryGetValue](https://docs.microsoft.com/aspnet/core/api/microsoft.extensions.caching.memory.imemorycache#Microsoft_Extensions_Caching_Memory_IMemoryCache_TryGetValue_System_Object_System_Object__) to check if the current time is in the cache. If the item isn't cached, a new entry is created and added to the cache with [Set](https://docs.microsoft.com/aspnet/core/api/microsoft.extensions.caching.memory.cacheextensions#Microsoft_Extensions_Caching_Memory_CacheExtensions_Set__1_Microsoft_Extensions_Caching_Memory_IMemoryCache_System_Object___0_).
The following code uses [TryGetValue](/dotnet/api/microsoft.extensions.caching.memory.imemorycache.trygetvalue?view=aspnetcore-2.0#Microsoft_Extensions_Caching_Memory_IMemoryCache_TryGetValue_System_Object_System_Object__) to check if a time is in the cache. If a time isn't cached, a new entry is created and added to the cache with [Set](/dotnet/api/microsoft.extensions.caching.memory.cacheextensions.set?view=aspnetcore-2.0#Microsoft_Extensions_Caching_Memory_CacheExtensions_Set__1_Microsoft_Extensions_Caching_Memory_IMemoryCache_System_Object___0_Microsoft_Extensions_Caching_Memory_MemoryCacheEntryOptions_).
[!code-csharp[](memory/sample/WebCache/Controllers/HomeController.cs?name=snippet1)]
The current time and the cached time is displayed:
The current time and the cached time are displayed:
[!code-html[](memory/sample/WebCache/Views/Home/Cache.cshtml)]
[!code-cshtml[](memory/sample/WebCache/Views/Home/Cache.cshtml)]
The cached `DateTime` value will remain in the cache while there are requests within the timeout period (and no eviction due to memory pressure). The image below shows the current time and an older time retrieved from cache:
The cached `DateTime` value remains in the cache while there are requests within the timeout period (and no eviction due to memory pressure). The following image shows the current time and an older time retrieved from the cache:
![Index view with two different times displayed](memory/_static/time.png)