File tree Expand file tree Collapse file tree 1 file changed +24
-31
lines changed
front/src/pods/embalse/api Expand file tree Collapse file tree 1 file changed +24
-31
lines changed Original file line number Diff line number Diff line change @@ -3,39 +3,32 @@ 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- }
6+ /**
7+ * Cached version of getReservoirInfoBySlug.
8+ * Revalidates every 60 seconds.
9+ */
10+ export const getReservoirInfoBySlugCached = unstable_cache (
11+ async ( slug : string ) : Promise < ReservoirInfo | null > => {
12+ try {
13+ const result = await contentIslandClient . getContent < ReservoirInfo > ( {
14+ language : "es" ,
15+ "fields. slug" : slug ,
16+ } ) ;
1717
18- return result ;
19- } ;
18+ if ( ! result ) {
19+ console . warn ( `Empty reservoir info for slug: ${ slug } ` ) ;
20+ return null ;
21+ }
2022
21- const fetchReservoirInfoBySlugCached = unstable_cache (
22- fetchReservoirInfoBySlug ,
23+ return result ;
24+ } catch ( error ) {
25+ console . warn (
26+ `Warning reservoir info for slug not available: ${ slug } ` ,
27+ error
28+ ) ;
29+ return null ;
30+ }
31+ } ,
2332 [ "reservoir-by-slug" ] ,
2433 { revalidate : 60 }
2534) ;
26-
27- /**
28- * Cached version of getReservoirInfoBySlug.
29- * Revalidates every 60 seconds.
30- * Only caches when data is available.
31- */
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