Does the "use cache" directive work on server actions and can a cached function be used inside proxy.ts?? #86931
Replies: 2 comments 5 replies
-
|
Move the cached function to a separate file without "use server" directive. The "use cache" directive does NOT work when used inline inside a file marked with "use server" at the top - the directives are mutually exclusive at file scope level. Create a new file (e.g., |
Beta Was this translation helpful? Give feedback.
-
|
This should most definitely work. I wonder how are you using it though? Is this in a Route Handler? I have: 'use server'
import { cacheTag } from 'next/cache'
async function foo() {
'use cache'
cacheTag('foo')
return 'foo'
}
export async function bar(){
const data = await foo()
return data
}Using it like: 'use client'
import { bar } from './action'
export default function Home() {
return (
<div>
<button onClick={() => bar().then(console.log)}>Foo</button>
</div>
);
}It works and builds, no issue. Maybe you've found some edge case where the bundler is not "bundling" correctly? care to show some more of how this is used? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I keep running into an error: cacheTag() can only be called inside a "use cache" function
Despite having used the "use cache" directive and setting cacheComponents to tre in my next config, I keep running into an error:
cacheTag() can only be called inside a "use cache" functionWhat am I doing wrong?
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions