Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect cache expiry checks in non-UTC time zones lead to premature cache invalidation #23

Open
eypcnckr opened this issue Oct 15, 2024 · 0 comments

Comments

@eypcnckr
Copy link

Functional impact

Yes. The bug results in incorrect cache expiration checks when the application runs in a time zone different from UTC, leading to stale or prematurely expired cache entries.

Minimal repro steps

  1. Create a web application project targeting .NET Framework 4.6.2.
  2. Decorate an endpoint with the OutputCacheAttribute class, using Duration=3600 (1 hour).
  3. Ensure the project is running in a time zone that is not UTC (e.g., UTC+3, as in Turkey).
  4. Implement caching logic in a class that uses OutputCacheModuleAsync.
  5. Make a request to the cached endpoint.

Expected result

The cache entry should remain valid for the full duration of 1 hour (3600 seconds) as specified, regardless of the server's time zone, and the endpoint response should come from the output cache.

Actual result

Cache entries are prematurely invalidated or stale data is served due to incorrect time zone handling, resulting in responses not coming from the output cache.

Further technical details

The root cause is the use of DateTime.Now for comparison instead of DateTime.UtcNow, which leads to incorrect evaluations of cache expiry in applications running in non-UTC time zones (e.g., Turkey UTC+3).

if (utcExpires > DateTime.Now) {

The problem is caused by the line above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant