How can I use IncrementalCache #209
-
Hi guys, can you help mt with my code. Cache-handler.js: const REVALIDATED_TAGS_KEY = 'sharedRevalidatedTags'; const pathToRedisCert = 'D:/WEB/search-client/.redis/root.crt'; const config = { const client = new Redis(config); client.on('connect', () => { IncrementalCache.onCreation(async () => {
}); module.exports = IncrementalCache;` In component: `import React from 'react'; async function getData() {
} But I see problem:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hey @BredyOST! I understood the problem. You did this in your component, but you don't need to do this: const cacheResult = await IncrementalCache.set('prices', prices) When building your Next.js app, the Let me explain how caching works. const pricesRes = await fetch('http://localhost:7777/prices/getAll', { next: { revalidate: 86400 }}) Upon the initial return of this fetch call, the result will be automatically cached in your Redis server using the strategy from the It's worth considering that the cache setup example you're using is designed for this Redis package. Ensure that the |
Beta Was this translation helpful? Give feedback.
-
Okay, thanks. |
Beta Was this translation helpful? Give feedback.
Hey @BredyOST! I understood the problem. You did this in your component, but you don't need to do this:
When building your Next.js app, the
IncrementalCache
class becomes part of the Next.js server. TheIncrementalCache
class must only be used in theCache-handler.
js file and not in any components.Let me explain how caching works.
Upon the initial return of this fetch call, the result will be automatically cached in your Redis server using the strategy from the
Cache-handler.js
file. The next time, instead of making a new fe…