Redis and Memcached object caches dramatically improve WordPress performance by storing database query results in fast memory. Post Views Counter Pro includes dedicated support for these persistent object cache systems, optimizing how view counts are tracked and synchronized with your database.

When a WordPress site uses a persistent object cache, Post Views Counter can buffer view counts in memory rather than writing each count to the database immediately. This reduces database load during traffic spikes and improves overall site performance.

How It Works

Post Views Counter’s object cache support operates through several coordinated mechanisms:

Count Buffering: View counts are temporarily stored in the object cache (Redis or Memcached) rather than being written to the database on every page load. This reduces database contention during high-traffic periods.

Scheduled Flushing: Cached counts are periodically flushed to the database through WordPress scheduled events, ensuring data persistence. The flush interval determines how often this synchronization occurs.

Cache Invalidation: When counts are flushed to the database, the relevant cache keys are cleared to prevent stale data from accumulating in memory.

The plugin hooks into WordPress scheduling to write buffered data to the database at controlled intervals, balancing performance with data freshness.

Setup

Prerequisites

Before enabling object cache support in Post Views Counter, verify your WordPress installation has a working persistent object cache:

  1. Redis or Memcached server installed and accessible to your web server
  2. Object cache drop-in (object-cache.php) present in your wp-content directory
  3. Connection verified through your hosting panel or a cache management plugin such as Redis Object Cache or W3 Total Cache

Without a functioning persistent object cache, enabling this setting provides no benefit. The standard WordPress in-memory cache does not persist across page loads and is not suitable for this feature.

Enabling Object Cache Support

  1. Navigate to Post Views > Counting > Performance & Caching
  2. Enable the Object Cache Support option
  3. Save changes

The setting takes effect immediately. Post Views Counter automatically detects your object cache backend and begins buffering view counts.

Configuration

Object Cache Support Setting

Property Value
Option ID object_cache
Location Post Views > Counting > Performance & Caching
Type Boolean (checkbox)
Default Disabled (false)
Availability Pro-only

Once enabled, the plugin stores view count increments in the object cache and flushes them to the database on a scheduled interval.

Flush Interval Behavior

The flush interval determines how long view counts remain in the object cache before being written to the database. This creates a tradeoff between performance and data freshness:

Shorter intervals (more frequent flushes):

  • Counts appear in reports and top posts lists more quickly
  • Lower risk of data loss if the object cache clears unexpectedly
  • Higher database write frequency

Longer intervals (less frequent flushes):

  • Maximum reduction in database writes
  • Better performance under heavy traffic loads
  • Slight delay before counts appear in statistics

The cache expiration timing defaults to 300 seconds (5 minutes). View counts are buffered for this duration before being flushed to the database.

Interaction with Counter Modes

Object cache support works alongside all counter modes:

  • PHP Mode: Counts are processed server-side and buffered through object cache before database writes
  • JavaScript Mode: Client-side requests are processed and cached server-side
  • REST API Mode: API endpoints benefit from cached count data
  • Fast AJAX: Optimized requests integrate with the object cache layer

For sites using page caching, combine object cache support with an appropriate counter mode. JavaScript Mode, REST API Mode, or Fast AJAX handle counting when page HTML is cached, while object cache optimizes the database writes on the backend.

Interaction with Caching Compatibility

The Caching Compatibility setting at Post Views > Counting > Performance & Caching works alongside object cache support. These settings address different aspects:

  • Caching Compatibility: Ensures counting works correctly when page caching plugins serve static HTML
  • Object Cache Support: Optimizes database writes by buffering counts in memory

Enable both when using page caching plugins to ensure page caches do not interfere with count tracking while the object cache handles count buffering efficiently.

Troubleshooting

Views Not Updating

If view counts appear stuck or not incrementing:

  1. Verify object cache is running: Check that your Redis or Memcached service is active and connected. Use your cache management plugin’s status screen or server monitoring tools.
  2. Check flush timing: Counts may be buffered in memory. Wait for the next flush interval before expecting counts to appear in the database.
  3. Review cache persistence: Ensure your object cache persists across page loads. The default WordPress in-memory cache does not persist and is not suitable for this feature.

Counts Lost After Cache Clear

If view counts reset when you clear your object cache:

  1. This indicates counts were buffered in memory but not yet flushed to the database
  2. Consider a shorter flush interval if data loss occurs frequently
  3. Schedule cache clears during low-traffic periods when possible
  4. Note that unexpected cache clears (server restarts, memory limits) can cause this issue

High Memory Usage

Object cache stores buffered counts in memory. On extremely high-traffic sites:

  1. Monitor your Redis or Memcached memory usage through your cache management tools
  2. Ensure adequate memory allocation for your object cache server
  3. Buffered count data is typically small, but sustained high traffic volumes can accumulate

Database Synchronization Issues

If counts are not appearing in the database:

  1. Verify WordPress cron is functioning correctly—the flush process relies on scheduled events
  2. Check for plugin conflicts that might disable WordPress cron
  3. Review your server error logs for database connection issues during flush operations

Debugging Cache Behavior

For developers investigating cache issues:

  • The pvc_object_cache_expire filter allows customization of cache expiration timing
  • The pvc_flush_cached_counts action triggers when counts are flushed to the database
  • The pvc_flush_signals_cache action handles cache clearing after flush operations
  • Inspect object cache keys related to post views using your cache inspection tools (Redis CLI, Memcached tools, or cache management plugins)