File tree Expand file tree Collapse file tree
front/src/pods/embalse/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,22 +3,39 @@ import { unstable_cache } from "next/cache";
33import type { ReservoirInfo } from "./embalse.api-model" ;
44import { contentIslandClient } from "@/lib" ;
55
6+ const fetchReservoirInfoBySlug = async (
7+ slug : string
8+ ) : Promise < ReservoirInfo > => {
9+ const result = await contentIslandClient . getContent < ReservoirInfo > ( {
10+ language : "es" ,
11+ "fields.slug" : slug ,
12+ } ) ;
13+
14+ if ( ! result ) {
15+ throw new Error ( `Empty reservoir info for slug: ${ slug } ` ) ;
16+ }
17+
18+ return result ;
19+ } ;
20+
21+ const fetchReservoirInfoBySlugCached = unstable_cache (
22+ fetchReservoirInfoBySlug ,
23+ [ "reservoir-by-slug" ] ,
24+ { revalidate : 60 }
25+ ) ;
26+
627/**
728 * Cached version of getReservoirInfoBySlug.
829 * Revalidates every 60 seconds.
30+ * Only caches when data is available.
931 */
10- export const getReservoirInfoBySlugCached = unstable_cache (
11- async ( slug : string ) : Promise < ReservoirInfo | null > => {
12- try {
13- return await contentIslandClient . getContent < ReservoirInfo > ( {
14- language : "es" ,
15- "fields.slug" : slug ,
16- } ) ;
17- } catch ( error ) {
18- console . warn ( `Warning reservoir info for slug not available: ${ slug } ` ) ;
19- return null ;
20- }
21- } ,
22- [ "reservoir-by-slug" ] ,
23- { revalidate : 60 } , // Check timing at least 1 hour
24- ) ;
32+ export const getReservoirInfoBySlugCached = async (
33+ slug : string
34+ ) : Promise < ReservoirInfo | null > => {
35+ try {
36+ return await fetchReservoirInfoBySlugCached ( slug ) ;
37+ } catch ( error ) {
38+ console . warn ( `Warning reservoir info for slug not available: ${ slug } ` ) ;
39+ return null ;
40+ }
41+ } ;
You can’t perform that action at this time.
0 commit comments