Fragment caching increasing database queries

You are using transient API which works storing data on wp_options table by default. That means that additional database queries will be performed to set the transient and to get the transient. With your code the number of queries should be less for non-logged in users in second and subsequent visits when the transient exists and it is valid.

If you use a persistent cache plugin (or you configure persistent cache at your own) the transient API will use WP_Object_Cache allowing the cached data be stored in memory instead of database, so there won’t be extra database queries.

Summary: using wp_cache functions will store cached data on memory and it is not persistent by default. In the other hand, transient API is persistent always and it use database by default. If you configure persistent cache, transient API and WP_Object_Cache return same results as transient API will use WP_Object_Cache.

Leave a Comment