diff --git a/src/pages/[locale]/api/hooks/collection-operation.astro b/src/pages/[locale]/api/hooks/collection-operation.astro index b33ae53..590e6fe 100644 --- a/src/pages/[locale]/api/hooks/collection-operation.astro +++ b/src/pages/[locale]/api/hooks/collection-operation.astro @@ -1,6 +1,6 @@ --- import { Collections } from "src/shared/payload/payload-sdk"; -import { refreshWordings } from "src/utils/cachedPayload"; +import { refreshCurrencies, refreshLocales, refreshWordings } from "src/utils/cachedPayload"; const auth = Astro.request.headers.get("Authorization"); @@ -15,6 +15,14 @@ switch (collectionSlug) { await refreshWordings(); break; + case Collections.Currencies: + await refreshCurrencies(); + break; + + case Collections.Languages: + await refreshLocales() + break; + default: return new Response(null, { status: 400, statusText: "Bad Request" }); } diff --git a/src/utils/cachedPayload.ts b/src/utils/cachedPayload.ts index 0e18532..1bc5965 100644 --- a/src/utils/cachedPayload.ts +++ b/src/utils/cachedPayload.ts @@ -18,7 +18,10 @@ export const refreshWordings = async () => { cache.wordings = await payload.getWordings(); }; -setInterval(async () => { - console.log("Refreshing cached Payload data"); - cache = await fetchNewData(); -}, 1000_000); +export const refreshCurrencies = async () => { + cache.currencies = (await payload.getCurrencies()).map(({ id }) => id) +}; + +export const refreshLocales = async () => { + cache.locales = await payload.getLanguages(); +}; \ No newline at end of file