A combination of the fact that TourCMS API use is subject to rate limits and the latency of contacting a third party server when displaying a web page means that it's best practice to implement some form of caching so that subsequent, identical requests to an API are served locally, rather than contacting the TourCMS server each time.
Sync to your own database or cache on the fly?
Broadly speaking there are two approaches you can take to caching API requests so that each request to your website/app does not equal a request to the TourCMS server:
Synchronising to your own database
If you are taking bookings using another reservation system or adding TourCMS sourced product to an existing database then this would likely be the approach you take.
We would suggest running jobs daily to import data into your database, we list some of APIs designed with this approach in mind on the main API page.
Caching on the fly
Generally speaking, if you are building a website/application searching and displaying TourCMS products then this is the approach you would take.
When a cacheable API request is made, the code on your site would check to see if the same request had been called recently and if so, display the outcome from the previous request, rather than contacting TourCMS again.
Some API methods can be cached longer than others, while some methods should not be cached. Here are some examples:
|API METHOD||EXAMPLE CACHE TIME|
|Search Tours||Cache for 30 minutes|
|Show Tour||Cache for 120 minutes|
|Dates & Deals||Cache for 30 minutes|
|Check availability||Do not cache|
|Booking Creation APIs||Do not cache|
These are of course only suggestions, you will likely find what works for you.
Implementing caching on the fly
Most modern frameworks or content management systems provide some form of caching functionality. Where available these should likely be used as they will likely be robust and proven.
It's best to store successful API in the cache - check for "error" or "OK".
A sample PHP implementation of caching on the fly using a basic file system cache is available on Github. It requires minimal configuration and is designed to be a drop in solution for those using our PHP wrapper.