Object Cache Integration: How Field Forge Reads Values
Field Forge reads field values through the WordPress object cache API (wp_cache_*). The first get_field() call for a post runs one query that loads all of the post’s top-level values, and keeps the result in the object cache, so the next calls for the same post run no query. The values live in their own table.
WordPress object cache basics
WordPress’s wp_cache_* functions provide a caching layer that sits between your code and the database. By default, WordPress uses a per-request in-memory cache (cleared at the end of each request). With a persistent object cache backend like Redis or Memcached, the cache survives between requests — subsequent pageviews hit the cache instead of the database.
On a high-traffic site with Redis:
- First pageview: fetches from database, stores in Redis
- Second pageview (same data): hits Redis, skips database entirely
- Third pageview: hits Redis
- …
For read-heavy workloads, a cache hit saves the database query.
Field Forge and object cache
Reading a top-level field goes through one cache entry per post:
// What get_field() does for a top-level field (simplified)
$values = wp_cache_get( (string) $post_id, 'fieldforge_values' );
if ( ! is_array( $values ) ) {
$values = $this->read_all_top_level_values( $post_id ); // one SELECT for the post
wp_cache_set( (string) $post_id, $values, 'fieldforge_values', 300 );
}
return $values[ $field_name ] ?? null;
- Cache keythe post ID
- Cache group
fieldforge_values(separate from other plugins) - Expiration300 seconds. There is no setting or filter for it
- Cache missone query loads every top-level value of the post and stores the lot
- Repeater and group rowsnested values are not in this entry; they are read from the database
Within one request the same map is also kept in memory, so repeated calls do not even reach the object cache.
Cache invalidation
When a field value is saved or deleted, Field Forge deletes the cache entry of that post and its in-memory copy:
- Immediatethe entry is deleted on save, and the next read rebuilds it
- Per postthe entry of the whole post is dropped, not only the changed field
- Hookedafter a write Field Forge fires
fieldforge/value_updated(post ID, field name) and, when all values of a post are deleted,fieldforge/values_deleted(post ID). Use them to clear a cache of your own:
add_action( 'fieldforge/value_updated', function ( $post_id, $field_name ) {
// Also clear related data
wp_cache_delete( "my_custom_cache:{$post_id}", 'my_plugin' );
}, 10, 2 );
Supported cache backends
Field Forge uses the standard wp_cache_* functions, so it works with whatever object cache the site has:
- A persistent backend (Redis, Memcached, APCu through an object cache drop-in): the entry survives between requests, and later page views skip the query.
- No persistent backend: WordPress’s default in-request cache. The values are still read once per post and request, but not kept between requests. No configuration needed.
Ready to try Field Forge?
Object cache integration is in the free Field Forge plugin and in the paid plans.