Introduction

Developer Preview
APIs in Developer Preview are subject to change and are not intended for use in production.
Send us your suggestions for improving this API. Your feedback is valuable to us.

 

Caching is a process that allows you to temporarily store data on Wix's infrastructure so it can be accessed faster, improving site performance. You can cache the return values of backend functions using the webMethod() function from wix-web-module, and for routers using the ok() function from wix-router. The Cache API provides functionality for invalidating your caches.

With the Cache API, you can invalidate the cached return values from your function calls, ensuring that your site displays the most current information. For instance, let's say you use the queryProducts() function and cache the response to display your products on your e-commerce site. If a product is discontinued, you should invalidate the cache to reflect this change. Once the cache is invalidated, it will be re-cached the next time the queryProducts() function is called. This prevents customers from attempting to purchase an item that is no longer available.

Learn more about cache invalidation for backend functions and routers.

To use the Cache API, import cache from the wix-cache-backend module:

Copy

Before you begin

You can invalidate your cached return values that were previously defined with tags when cached. Your cache is automatically invalidated when:

  • The cache's time to live (TTL) expires.
  • You republish your site with a code change.

Permissions information

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.

Terminology

  • Return value cache: API call return value that is temporarily stored on Wix's infrastructure.
  • Tag: Used to identify which cached return values to invalidate.
Did this help?