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 your backend function calls using the webMethod() function from the wix-web-module. The Cache API provides functionality for invalidating your backend function's 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.

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

Copy
1

Before you begin

You can invalidate your functions's 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.
Was this helpful?
Yes
No