Tweak cache tag handling
This commit is contained in:
parent
6e436c7ee4
commit
c7fdfd1df2
12
src/cache/index.ts
vendored
12
src/cache/index.ts
vendored
@ -14,7 +14,7 @@ const TAG_PHOTOS_COUNT = 'photos-count';
|
|||||||
const TAG_TAGS = 'tags';
|
const TAG_TAGS = 'tags';
|
||||||
|
|
||||||
const getPhotosCacheTags = (options: GetPhotosOptions = {}) => {
|
const getPhotosCacheTags = (options: GetPhotosOptions = {}) => {
|
||||||
const tags = [TAG_PHOTOS];
|
const tags = [];
|
||||||
|
|
||||||
const {
|
const {
|
||||||
sortBy,
|
sortBy,
|
||||||
@ -37,7 +37,7 @@ const getPhotosCacheTags = (options: GetPhotosOptions = {}) => {
|
|||||||
return tags;
|
return tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
const tagForPhoto = (photoId: string) => `photo-${photoId}`;
|
const getPhotoCacheTag = (photoId: string) => `photo-${photoId}`;
|
||||||
|
|
||||||
export const revalidatePhotosTag = () =>
|
export const revalidatePhotosTag = () =>
|
||||||
revalidateTag(TAG_PHOTOS);
|
revalidateTag(TAG_PHOTOS);
|
||||||
@ -45,8 +45,8 @@ export const revalidatePhotosTag = () =>
|
|||||||
export const getPhotosCached: typeof getPhotos = (...args) =>
|
export const getPhotosCached: typeof getPhotos = (...args) =>
|
||||||
unstable_cache(
|
unstable_cache(
|
||||||
() => getPhotos(...args),
|
() => getPhotos(...args),
|
||||||
getPhotosCacheTags(...args), {
|
[TAG_PHOTOS, ...getPhotosCacheTags(...args)], {
|
||||||
tags: getPhotosCacheTags(...args),
|
tags: [TAG_PHOTOS, ...getPhotosCacheTags(...args)],
|
||||||
}
|
}
|
||||||
)().then(parseCachedPhotosDates);
|
)().then(parseCachedPhotosDates);
|
||||||
|
|
||||||
@ -61,8 +61,8 @@ export const getPhotosCountCached: typeof getPhotosCount = (...args) =>
|
|||||||
export const getPhotoCached: typeof getPhoto = (...args) =>
|
export const getPhotoCached: typeof getPhoto = (...args) =>
|
||||||
unstable_cache(
|
unstable_cache(
|
||||||
() => getPhoto(...args),
|
() => getPhoto(...args),
|
||||||
[TAG_PHOTOS, tagForPhoto(...args)], {
|
[TAG_PHOTOS, getPhotoCacheTag(...args)], {
|
||||||
tags: [TAG_PHOTOS, tagForPhoto(...args)],
|
tags: [TAG_PHOTOS, getPhotoCacheTag(...args)],
|
||||||
}
|
}
|
||||||
)().then(photo => photo ? parseCachedPhotoDates(photo) : undefined);
|
)().then(photo => photo ? parseCachedPhotoDates(photo) : undefined);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user