Caching allows you to temporarily store the return values of backend API calls and successful router calls on Wix's infrastructure, enabling quicker access to the data and improved site performance. While caching is effective, it’s important to invalidate caches when necessary to ensure that data always remains up to date. This helps preserve accuracy and prevents visitors from seeing outdated content.
The Cache API provides functionality for invalidating web method caches and router caches. Consider invalidating your caches when there are significant changes to your site's content or when your site pages display time-sensitive data. For example, if a product on your e-commerce site becomes out of stock, invalidating the cache of the web method that displays your products ensures that visitors see the most current status.
Learn more about web method caching and router caching.
To use the Cache API, import cache
from the wix-cache-backend
module:
import { cache } from `wix-cache-backend`;
You can invalidate your caches that were previously defined with tags. Your cache is automatically invalidated when:
Functions in the Cache API are restricted and only run if you elevate permissions using the wix-auth
elevate()
function.
Warning: Elevating a function allows it to be called by any site visitor. Exercise caution to prevent security vulnerabilities.