Havenlytics cache management spans several layers — a central transient facade, an engine cache, and multiple object-cache groups — all gated behind a single “is caching enabled” switch. This guide explains each layer, the key and TTL conventions, where caches are invalidated, the cache-related hooks, and the API you use to clear caches programmatically.
Note: Caching is globally controlled by
hvnly_is_cache_enabled()(the single source of truth, reading thehvnly_cache_enabledoption). When it returnsfalse, the facade’s read/write short-circuit and nothing is cached.
Cache layers
1. CacheManager — the transient facade
HvnlyNab\Core\CacheManager (includes/Core/CacheManager.php) is the centralized transient cache. All keys are prefixed _transient_hvnly_ and passed through sanitize_key(). Optional GZIP compression is gated by the hvnly_cache_compression option. Purges use a direct SQL DELETE against option_name LIKE '_transient_hvnly_%'.
| Method | Purpose |
|---|---|
set_transient( $key, $value, $ttl = HOUR_IN_SECONDS ) | Write a value (no-op when caching disabled). |
get_transient( $key ) | Read a value (returns false when disabled). |
delete_transient( $key ) | Delete a single entry. |
clear_all_cache() | Purge all hvnly_ transients. |
clear_transients_by_pattern( $pattern ) | Purge entries matching a pattern. |
clear_expired_cache() | Remove expired entries. |
get_cache_stats() | Return cache statistics. |
2. HvnlyEngine — engine cache
The engine (includes/HvnlyEngine.php) provides an engine-level cache (set_cache(), get_cache(), clear_all_cache(), cleanup_expired_cache()) with hit/miss tracking. It is reached through the facade functions hvnly_clear_cache(), hvnly_get_cache_stats(), and hvnly_transients_available().
3. Object-cache groups (wp_cache_*)
| Group | Used by | Notes |
|---|---|---|
havenlytics | includes/Helpers.php | Ratings, max price, term labels/IDs (≈1 hour). |
hvnly_property_queries | includes/Frontend/Query/PropertyQueryCache.php | Dual-layer wp_cache + transient (prefix hvnly_pquery_). TTL clamped 1–15 min (default 10; filter hvnly_property_query_cache_ttl). Empty results cached 60s. |
hvnly_property_views | includes/Frontend/PropertyViewTracker.php | View-count caching. |
hvnly_analytics | includes/Analytics/AnalyticsService.php | Analytics data (900s / 15 min). |
options | Builders, import, migrations | Storage-key option caching. |
Transient key & TTL reference
| Key / prefix | TTL | Source |
|---|---|---|
hvnly_dynamic_css | 1 day | Core/DynamicStyleGenerator.php |
hvnly_sidebar_filters_data | 12 hours | Frontend/ViewModels/SidebarSearchFilters.php |
hvnly_unique_property_ids | 12 hours | Functions/utility-functions.php |
hvnly_import_remote_media_ok | 10 minutes | Functions/utility-functions.php |
hvnly_ca_unread_inquiry_count | 1 minute | ContactAgent/InquiryUnreadCounter.php |
_transient_hvnly_{shortcode-tag}_* | 1 hour | Frontend/Shortcodes/AbstractShortcode.php |
hvnly_has_gravatar_{md5(email)} | 1 day | Common/AvatarService.php |
Invalidation points
HvnlyNab\Core\CacheInvalidator—invalidate()is hooked tosave_post_hvnly_propertyanddeleted_post_meta, clearing the search, sidebar, and property-query caches when a property changes.Frontend\AjaxHandler— hookssave_post_hvnly_property,deleted_post_meta, and thecreated_term/edited_term/delete_termevents to clear property and taxonomy caches.- View models —
SidebarSearchFiltersandSearchFiltersexposeclear_*_cache()methods; both also deletehvnly_unique_property_ids. hvnly_clear_all_cache()— clears all search caches and fireshvnly_cache_cleared.
Cache hooks
| Hook | Type | Purpose |
|---|---|---|
hvnly_property_query_cache_key | filter | Filter the property-query cache key. |
hvnly_property_query_cache_ttl | filter | Filter the query cache TTL (clamped 1–15 min). |
hvnly_search_cache_key / hvnly_search_cache_duration | filter | Filter the search cache key / TTL. |
hvnly_sidebar_cache_duration | filter | Filter the sidebar cache TTL. |
hvnly_cache_cleared | action | Fires after all cache is cleared. |
hvnly_cache_pattern_cleared | action | Fires after pattern-based clear. |
hvnly_property_query_cache_set / hvnly_property_query_cache_invalidated | action | Fires when a query result is cached / the generation is bumped. |
The clear-cache API
<?php
// Programmatic clears:
HVNLY_NAB()->clear_cache(); // clears the engine cache
hvnly_clear_all_cache(); // clears all search/plugin caches + fires hvnly_cache_cleared
// Guard your own cache work behind the SSOT switch:
if ( hvnly_is_cache_enabled() ) {
\HvnlyNab\Core\CacheManager::set_transient( 'my_addon_data', $data, 10 * MINUTE_IN_SECONDS );
}
The admin UI clears caches over AJAX via the hvnly_clear_cache action, protected by the hvnly_cache_nonce nonce and the manage_options capability.
Filter the query cache TTL
<?php
add_filter( 'hvnly_property_query_cache_ttl', function ( $ttl ) {
return 5 * MINUTE_IN_SECONDS; // shorter cache for very dynamic listings
} );
Invalidate your own cache in sync with Havenlytics
<?php
add_action( 'hvnly_cache_cleared', function () {
delete_transient( 'my_addon_derived_cache' );
} );
Best practices
- Always guard writes with
hvnly_is_cache_enabled()so your add-on respects the site’s caching setting. - Use the
CacheManagerfacade (keys auto-prefixed and sanitized) rather than rawset_transient(), so your entries are purged by the plugin’s clear routines. - Hook
hvnly_cache_cleared/hvnly_property_query_cache_invalidatedto keep derived caches consistent.
Performance recommendations
Performance: The property query cache (
hvnly_property_queries) is the highest-leverage layer — leave it enabled in production. Random-order queries (orderby=rand) bypass it by design, so avoid random ordering on high-traffic archives.
Common mistakes
- Writing to caches without checking
hvnly_is_cache_enabled(), so data is cached even when the admin disabled caching. - Using raw transient keys that the plugin’s purge routines don’t match, leaving stale data after a clear.
- Expecting query results to update instantly — they are cached for up to 15 minutes unless a property save invalidates them.