invalidateCache( )
Invalidates the cache for a site.
Description
Calling the invalidateCache()
function submits a request to invalidate (clear) the site cache.
The function returns a Promise that resolves when the invalidation request is accepted (or rejected). Note that the
invalidation process normally takes a few seconds to propagate.
Most Wix sites are cached by default to provide better performance. In cases where your site changes without publishing, caching may adversely affect your site. For example, if your site fetches and displays data from a 3rd-party service, you might experience the following issues on a cached site:
- Updated data is not displayed.
- Updated data is not exposed to bots, hurting SEO.
You can prevent such issues by invalidating your site's cache following a data update.
Authorization
Request
This endpoint does not take any parameters
Response Object
Fulfilled - When the site cache invalidation request is accepted. Rejected - An error message.
Returns an empty object.
Status/Error Codes
Was this helpful?
1import wixSiteBackend from 'wix-site-backend';23export function invalidateCache() {4 return wixSiteBackend.invalidateCache();5}
1/***************************************2 * Backend code - myModule.jsw *3 ***************************************/45 import wixSiteBackend from 'wix-site-backend';6 import { getJSON } from 'wix-fetch';78 export function invalidateCache() {9 return wixSiteBackend.invalidateCache();10 }1112 export function fetchData() {13 return getJSON("https://someapi.com/api/someendpoint");14 }1516 let json = fetchData();1718 // This function is triggered by a 3rd-party service19 // when data changes (for example, via webhook)20 export function updateData() {21 json = fetchData();22 invalidateCache();23 }2425 export function getData() {26 return json;27 }2829 /********************30 * Client-side code *31 ********************/3233 import { getData } from 'backend/myModule';3435 $w.onReady(function () {36 return getData()37 .then((json) => {38 $w('#myTextElement').text = json.someData[0].description;39 })40 .catch((error) => {41 console.log(error);42 });43 }