Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions astro.sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const sidebar = [
group('reference.experimental', {
items: [
'reference/experimental-flags',
'reference/experimental-flags/route-caching',
'reference/experimental-flags/client-prerender',
'reference/experimental-flags/content-intellisense',
'reference/experimental-flags/chrome-devtools-workspace',
Expand Down
30 changes: 27 additions & 3 deletions src/content/docs/en/reference/content-loader-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,32 @@ export function myLoader(config): LiveLoader<Product, ProductEntryFilter, Produc
}
```

You can then use these hints in your pages:
You can then use these hints in your pages. If you have [experimental route caching](/en/reference/experimental-flags/route-caching/) enabled, pass cache hints directly to `Astro.cache.set()`:

```astro title="src/pages/store/[id].astro"
---
export const prerender = false; // Not needed in 'server' mode

import { getLiveEntry } from 'astro:content';

const { entry, error, cacheHint } = await getLiveEntry('products', Astro.params.id);

if (error) {
return Astro.redirect('/404');
}

// Pass cache hints to route caching
if (cacheHint) {
Astro.cache.set(cacheHint);
}
Astro.cache.set({ maxAge: 300 });
---

<h1>{entry.data.name}</h1>
<p>{entry.data.description}</p>
```

Without route caching enabled, you can use cache hints to set response headers manually for your own caching strategy:

```astro title="src/pages/store/[id].astro"
---
Expand All @@ -624,7 +649,6 @@ if (error) {
return Astro.redirect('/404');
}

// Apply cache hints to response headers
if (cacheHint?.tags) {
Astro.response.headers.set('Cache-Tag', cacheHint.tags.join(','));
}
Expand All @@ -639,7 +663,7 @@ if (cacheHint?.lastModified) {
```

:::note
Cache hints only provide values that can be used in other parts of your project and do not automatically cause the response to be cached by Astro. You can use them to create your own caching strategy, such as setting HTTP headers or using a CDN.
Cache hints do not automatically cause the response to be cached by Astro. They provide values you can pass to [route caching](/en/reference/experimental-flags/route-caching/) or use to implement your own caching strategy.
:::

## Distributing your loader
Expand Down
Loading