There are a lot of tools and options available in Views that facilitate the building of complex queries, in order to produce the desired output. Sometimes, the execution of these queries can become processor resource-intensive and time-consuming, as the output complexity increases.
For this purpose, Views plugin provides a caching mechanism that allows Views with long queries to be rendered faster, since the whole output is stored in the database.
Caching is not available for all Views, as the frontend rendering of a View may depend on many elements. For the eligible Views, this feature is turned on by default, but you can easily turn it off, by selecting the corresponding option when you insert a View.
Cache is automatically turned off for Views when:
- The user is loading a page, different from the first one, in a paginated View.
- The user is loading a custom search View after performing a search.
- Debug mode is enabled on the Toolset->Settings page’s Front-end tab, in the Development section. Development screen and the current user has the permission to see the debug output.
- The View shortcode has any attribute other than name, id or target_id, since the results of this View will be modified, thus preventing the user from viewing the cached output.
- target_id has been set to self, since we do not know what the actual target of the custom search is.
- The View has an option for random sorting of the results.
- The View is nested or has a filter or an option that depends on the current page, current user, or current archive data. Note that this invalidates cache when Don’t include current page in query result query option is checked.
- The View has a filter or option that requires a value from a registered framework option, since this value can be changed outside of the Views
- Filter wpv_filter_disable_caching is used to manually disable the caching system.
- WPML is active, since the same View can produce different results for different languages.
Things that also change the content or the status of posts, terms, or users will invalidate cache automatically. For example, when you update a post or create a new taxonomy term. Views automatically invalidates cache after 24 hours.