dotnet / dotnet/AspNetCore.Docs

AbsoluteExpiry of caller overridden/ignored if child called that causes cache entry with shorter expiry

Open
#10,962 7 comments 0 reactions 0 assignees View on GitHub
area-runtime-extensions doc-bug re-Aditya Source - Docs.ms Top10
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 3h
Merged PRs (30d)
97

Description

If method A caches for 12 hours and calls method B which caches for 5 minutes, the result for method A will only be cached for 5 minutes.

Logically this appears to make sense but this happens without the caller for Method A knowing about it. Consider the situation where method A goes on to make calls to a system that has a quota that mustn't be called too frequently. There should at least be an error if Method A has set an absolute expiry that is subsequently ignored/overridden by the call to Method B.

It relates to this change:
https://github.com/aspnet/Caching/commit/f15fb804cdc2e14f9a64896817f3c6c343110820#diff-9968fc5543acfd05fa60089bd344679bR102

The actual behaviour appears to contradict the bullet point above but that could depend on your interpretation of which is child and which is parent in the scenario I've described: "When one cache entry is used to create another, the child copies the parent entry's expiration tokens and time-based expiration settings. The child isn't expired by manual removal or updating of the parent entry."

I've put a code example here: https://sartorialsolutions.wordpress.com/2019/02/15/aspnetcore-memorycache-magic-dependencies-and-danger/

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 13f5f8f9-18dd-9c12-9ed1-fcc6b44ba7fd
* Version Independent ID: 640b4f36-5886-7b69-1c95-cfc8574a02fd
* Content: [Cache in-memory in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-2.2#cache-dependencies)
* Content Source: [aspnetcore/performance/caching/memory.md](https://github.com/aspnet/Docs/blob/master/aspnetcore/performance/caching/memory.md)
* Product: **aspnet-core**
* GitHub Login: @Rick-Anderson
* Microsoft Alias: **riande**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.