Skip to content

SWR prevent cache expiration #3110

@julbd

Description

@julbd

Environment

Nitro 2.10.4

Reproduction

  routeRules: {
    '/': { swr: true, maxAge: 60, staleMaxAge: 60 },
  },

Describe the bug

The current implementation prevent cache clearing when swr is enabled.

https://github.com/nitrojs/nitro/blame/4a57c822d98701ef8f7a07aff7eb60be4c1888e2/src/runtime/internal/cache.ts#L124

This make the cached value being indefinitely reused and, in some case, massive cache accumulation. For heavy endpoint/functions, disabling swr may not be an option, as it can lead to extended unavailability.

The expected behavior would be to calculate and use the correct ttl using staleMaxAge.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions