1

I have pricing that I load from my billing system whmcs to my WordPress website using PHP.

I wanted to know if there is a way I can preload it for it to load nicely or cache only that page or something that will make the page just show without loading slowly.

Thanks

2
  • How often is the pricing updated in your billing system? Jun 10, 2019 at 21:29
  • @ChristopherJones Pricing is changed often. It links to the exchange rate. Jun 12, 2019 at 10:50

1 Answer 1

3

WordPress has Transient and Object Cache APIs available. In a default WordPress install, Transients are stored in the database while Object Cache is stored in memory for the duration of the request. You can change this configuration to using something like Redis, Memcache, or APC to store and access this faster.

In your case, you'd want to use Transients.

Here's a good example from the Transient API Codex:

<?php
// Get any existing copy of our transient data
if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) {
    // It wasn't there, so regenerate the data and save the transient
     $special_query_results = new WP_Query( 'cat=5&order=random&tag=tech&post_meta_key=thumbnail' );
     set_transient( 'special_query_results', $special_query_results, 12 * HOUR_IN_SECONDS );
}

// Use the data like you would have normally...
?>
3
  • Hi MikeNGarrett, Thanks for your solution. I will try and give you feedback. Jun 12, 2019 at 10:51
  • My brain leans towards setting up a cronjob to hit a simple script that will get your pricing, and then pair it with @MikeNGarrett's idea of storing it with the Transient API. I like the idea of a cron so that you are not forcing the user's page load to go get your pricing data. All that is done behind the scene. So on page load, you are just running get_transient() Jun 12, 2019 at 15:53
  • That's fine, but transients can be cleared or lost. Make sure you handle this scenario. Jun 12, 2019 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.