Knowledgebase
Maestrel > Help Desk > Knowledgebase

Browse our knowledgebase...




 
Knowledgebase » How to ... »

How to use caching with HBook?

Answer

Using a WordPress caching plugin or the built-in cache plugins from your hosting requires adjustment to work nicely with HBook. There are two aspects concerned : 

  • the caching of HBook ical calendar URLs : it is important that these URLs are not cached so it is always an up-to-date calendar that is returned when external platforms(AirBnb, Booking.com, etc.) call your HBook ical calendar URLs.
  • the calendars displayed on your website, be it the "Availability calendar" ([hb_availability] shortcode or block) or the booking form date picker ([hb_booking_form] shortcode or block). You wish to always show accurate availability in your front-end HBook calendars.

Depending on your website structure, and on the caching tool that are in place on your website, we recommend implementing the following : 

  • Exclude from the cache any URLs that should not be cached. You should exclude URLs of pages where you have a HBook availability calendar. This is the easiest option and is suitable if you do not have HBook calendars on many pages of your website
  • use a function from your caching tool to flush the cache whenever a reservation has been received or modified and whenever a blocked date has been added. This option is more appropriate if you have many pages on your website that display HBook calendars. And it is as well the best way to proceed for the HBook ical calendar URLs, since not all caching tools allow having query parameter in their settings to Exclure URLs from the cache.

You can use our filters to execute the function that will clear/flush cache, each time a reservation is received or updated. The filters that should be used are "hb_reservations_updated" and "hb_blocked_accom_updated".  You can consult the list of available filters in our documentation.

Please find below a couple of examples for popular caching tools :

LiteSpeed (documentation reference)

  • Exclude "feed" from the cache in "Do not cache query strings" in "Exclude" settings for the Cache.
  • Use a function - Add this code  in the file functions.php of your child theme :
function my_custom_flush_cache() {
do_action( 'litespeed_purge_all' );
}
add_filter( 'hb_reservations_updated', 'my_custom_flush_cache' );
add_filter( 'hb_blocked_accom_updated', 'my_custom_flush_cache' );

SG Optimizer SuperCacher

  • You can check the section "Exclude URLs from Caching" of this article from SG Optimizer cache to exclude pages.
  • Use a function - Add this code  in the file functions.php of your child theme:

function my_custom_flush_cache() {
   if (function_exists('sg_cachepress_purge_cache')) {
           sg_cachepress_purge_cache();
    }
}
add_filter( 'hb_reservations_updated', 'my_custom_flush_cache' );
add_filter( 'hb_blocked_accom_updated', 'my_custom_flush_cache' );

 

WPFastest cache (documentation reference)

  • You can check this article from WPFastest cache to exclude pages.
  • Use a function - Add this code  in the file functions.php of your child theme :
function my_custom_flush_cache() {
if ( function_exists( 'wpfc_clear_all_cache' ) ) { wpfc_clear_all_cache();
} } add_filter( 'hb_reservations_updated', 'my_custom_flush_cache' ); add_filter( 'hb_blocked_accom_updated', 'my_custom_flush_cache' );

WPRocket

  • You can check this article from WPRocket to exclude pages.
  • Use a function - Add this code  in the file functions.php of your child theme:
function my_custom_flush_cache() {
    if ( function_exists( 'rocket_clean_domain' ) ) {
rocket_clean_domain();
     }
}
add_filter( 'hb_reservations_updated', 'my_custom_flush_cache' );
add_filter( 'hb_blocked_accom_updated', 'my_custom_flush_cache' );

WP Super Cache

  • You can check this article from WP Super Cache to exclude pages.
  • Use a function - Add this code  in the file functions.php of your child theme:
function my_custom_flush_cache() {
    if ( function_exists( 'wp_cache_clear_cache' ) ) {
wp_cache_clear_cache();
     }
}
add_filter( 'hb_reservations_updated', 'my_custom_flush_cache' );
add_filter( 'hb_blocked_accom_updated', 'my_custom_flush_cache' );

If you don't know whether the cache plugin you wish to use have this flush function that can be called, you can browse their documentation or get in touch with their support team.
Related articles I use WooCommerce and a user with HBook role is redirected to WooCommerce "my-account" page. How to disable this redirection?
How to use MailChimp with HBook? May I have a MailChimp newsletter subscription checkbox in the form?
Why are my emails not received? Why do you recommend SMTP for my WordPress emails?
How to sync HBook with AirBnb? How to set up the iCal synchronization with AirBnb?
Themes Booking Plugin Pricing Blog Contact