Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

this.cache(...) in preload #415

@Rich-Harris

Description

@Rich-Harris

At present there's no way to set a cache header for a page. It might be useful to be able to do this:

export default {
  async preload({ params }) {
    this.cache('max-age', 30 * 60 * 1000); // cache for 30 minutes
    await this.fetch(...).then(...);
  }
};

(An interesting question that arises is whether that should change behaviour on the client as well. Should the browser cache the preloaded data for the specified duration and reuse it if the same URL is visited later? This would make some navigations faster but would increase memory usage and introduce a danger of mutation bugs, so perhaps it's better to rely on the service worker.)

Or would it be better to have a more generic this.headers({...}) function?

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