Using JobRelay with caching Plugins
In this article
JobRelay works well with WordPress caching plugins, but there is one important consideration: your cache needs to be cleared when new jobs arrive. Otherwise, visitors may continue to see an outdated list of jobs.
This page explains why cache clearing matters and outlines the recommended approaches for keeping job listings fresh.
Why cache clearing is required
Most WordPress caching plugins (page cache, full‑page cache, static HTML cache, etc.) store a snapshot of your pages to improve performance. When JobRelay imports new jobs:
- The job data in WordPress is updated immediately
- Cached pages that display jobs may not update automatically
- Visitors may see stale job listings until the cache expires or is manually cleared
To avoid this, the cache must be cleared (or bypassed) when new jobs are imported.
Recommended approaches
Option 1: Clear cache after each JobRelay import (recommended)
The safest approach is to clear the cache automatically after JobRelay finishes adding, removing or updating jobs.
Most popular caching plugins support programmatic cache clearing, for example:
- WP Rocket
- W3 Total Cache
- WP Super Cache
- LiteSpeed Cache
- Cache Enabler
JobRelay exposes WordPress hooks that can be used to trigger cache clearing once an import completes.
Why this works well
- Guarantees job listings update immediately
- Works with full‑page caching
- No impact on visitors
Option 2: Exclude job listing pages from cache
Some sites choose to exclude job listing pages (or job search results) from caching entirely.
Typical exclusions include:
- Job listing archive pages
- Job search result pages
- Filtered or paginated job URLs
Pros
- No cache clearing required
- Always shows real‑time job data
Cons
- Reduced performance on high‑traffic job pages
- Not ideal for large job boards
This approach is usually best for small sites or low‑traffic job listings.
Option 3: Use short cache lifetimes
You can configure your cache to expire job page caches quickly (for example, every 5–10 minutes).
Pros
- Simple to configure
- No custom code required
Cons
- Jobs may appear late
- Less predictable update timing
This option is acceptable if near‑real‑time updates are not critical.
Clearing cache via JobRelay hooks
JobRelay provides action hooks that fire after a successful import. These can be used to clear caches automatically.
Example use cases:
- Clear the entire site cache
- Clear only job listing pages
- Clear only specific URLs
Your developer can connect JobRelay’s import completion hook to the cache‑clearing function provided by your caching plugin.
Below is a simple code snippet to start you off.
<?php
/**
* Clears the job cache.
*
* @param integer $job_post_id The newly created post ID for the new job.
* @param array $job_data The array of job data sent over.
*/
function hd_clear_cache_after_job_added_updated( $job_post_id, $job_data ) {
/**
* Run your cache clearing code here.
*/
}
add_action( 'jobrelay_wpcon_job_inserted_complete', 'hd_clear_cache_after_job_added_updated', 999, 2 );
In the part of the code above where it states “run your cache clearing code here“, this is where you would call the specific function for clearing the cache depending on which caching plugin you are using.