Query caching improves a site's performance by automatically storing frequently requested data results. When visitors trigger queries whose results are already cached, the system serves the cached data instead of querying the database again, significantly reducing response times.
The Data API automatically caches certain query results to a Content Delivery Network (CDN). Understanding when caching occurs and how to work with it helps you optimize site performance.
Not all queries are cached. The Data API only caches query results when specific conditions are met, ensuring that cached data remains accurate and secure.
Query results are cached when all of the following conditions are true:
consistentRead: true.Cache invalidation ensures that visitors receive up-to-date data by automatically clearing cached results when the underlying data changes.
The cache is automatically cleared in the following scenarios:
To optimize caching performance, consider separating collections into ones with stable data that doesn't change often and others with dynamic data that does change often. This allows the system to cache stable data for longer periods while invalidating dynamic data more frequently.
Cache invalidation can take a few seconds to complete, which may make eventual consistency effects more noticeable. If you need the most up-to-date data immediately after a change, override eventual consistency using the consistentRead parameter.
The monitoring dashboard provides insights into a site's performance, including the effects of query caching.
Cached query requests are tracked in Wix's monitoring system but aren't currently displayed in the monitoring dashboard. This means: