Cache Shortutility
utility
The strategy instructs caches to store data for 1 second, and
data for an additional 9 seconds. Note: these time values are subject to change.
Learn more about data fetching in Hydrogen.
Anchor to cacheShort-parametersParameters
Anchor to overrideOptions
overrideOptions
Anchor to cacheShort-returnsReturns
AllCacheOptions
maxAge
number
The maximum amount of time in seconds that a resource will be considered fresh. See max-age
in the MDN docs.
mode
string
The caching mode, generally public
, private
, or no-store
.
sMaxAge
number
Similar to but specific to shared caches. See
s-maxage
in the MDN docs.
staleIfError
number
Indicate that the cache should serve the stale response if an error occurs while revalidating the cache. See stale-if-error
in the MDN docs.
staleWhileRevalidate
number
Indicate that the cache should serve the stale response in the background while revalidating the cache. See stale-while-revalidate
in the MDN docs.
Was this section helpful?
Example code
import {CacheShort} from '@shopify/hydrogen';
export async function loader({context}) {
const data = await context.storefront.query(
`#grahpql
{
shop {
name
description
}
}
`,
{
cache: CacheShort(),
},
);
return data;
}