Open lwang-79 opened 2 months ago
Hello, @lwang-79 👋. Can you clarify if you're experiencing this in Dev Mode? It's possible this behavior is due to how React's development mode will invoke the useEffect hook twice. It doesn't look like you're running a "cleanup function" that would help with this, so can you see if the following changes the behavior:
useEffect(() => {
Cache.setItem("test", "test")
const timer = setTimeout(() => {
Cache.clear().then(() => {
console.log("cleared")
})
.catch(e => {
console.log("error", e)
})
}, 2000)
// Cleanup function
return () => {
clearTimeout(timer)
}
}, []);
Alternatively, you could test this in production mode (rather than development mode) and it should also make the Cache.clear()
call work as expected. Let me know if this helps!
Hi @cwomack, thank you for checking this issue. I have verified that it's not due to the React restrict mode.
@lwang-79, appreciate the quick follow up. After testing this further on our side, we've confirmed there is a bug in v6 of Amplify with Cache.clear()
. The cache is not updating it's state as expected after some. refactoring we did in the latest major version.
Thank you for opening this and helping us identify the bug! We'll update this issue with progress as it's made.
@lwang-79 and anyone else following this issue, a fix for this was released in v6.6.6 of Amplify. Please upgrade to that (or the latest v6.6.7) and let us know if this issue is resolved! Thanks.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Cache
Amplify Version
v6
Amplify Categories
Not applicable
Backend
None
Environment information
Describe the bug
The Cache.clear() API doesn't work, the cache items are not removed from local storage after this API is called.
Cache.removeItem()
API works but need a quick way to remove all cache items after user log out.Expected behavior
All cache items created by Amplify Cache util can be removed.
Reproduction steps
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response