Adjusting YouTube API Cache Time
Learn how to adjust the YouTube API cache duration in JetBlog. Use filters to adjust the default 6-hour cache time and streamline API requests.
Before you start, check the tutorial requirements:
- Elementor (Free version)
- JetBlog plugin installed and activated
This article explains how to adjust the YouTube API cache time in the WordPress JetBlog plugin using filters. It also describes how to test the changes and handle cached data.
By default, JetBlog caches YouTube API responses for six hours to reduce the number of API requests and improve performance. While this works well for most cases, sometimes you may want fresher data or a longer storage period. Let’s have a look at how to change it.
Clear Transients and Disable Caching
First, to verify caching behavior, you need to clear any existing transients. To do this, install the Delete Expired Transients plugin.
Proceed to WordPress Dashboard > Plugins > Add Plugin and search for the Delete Expired Transients plugin. Click the “Install Now” button next to the needed plugin, and then the “Activate” button.
When the plugin is activated, go to WordPress Dashboard > Tools > Delete Transients. Select the “all transients” option and click the “Delete” button.
Then, proceed to the page where the Video Playlist widget is added. Open the widget’s settings and scroll down to the Disable Caching toggle. Ensure that it’s off.
Click the “Publish” button and proceed to the front end.
On the first reload, requests are being sent to the YouTube API.
When you reload the page again, there will be no requests — this means the data has been cached and is now being loaded from the cache.
Adjust Cache Time with Filters
By default, JetBlog caches the YouTube API response for six hours. You can use this filter to shorten or extend that duration.
For that, proceed to the functions.php file of your current theme and add the following code:
add_filter('jet_blog_list_cache_ttl_hours', fn($h)=>1);
add_filter('jet_blog_video_cache_ttl_hours', fn($h)=>1);
These filters define the duration for which the video details cache of the Video Playlist widget is stored. The code sets the cache time for the Video Playlist widget to one hour. After one hour, the widget will request fresh data from the YouTube API. You can change the duration according to your needs.
Now, when we reload the page with the Video Playlist widget in an hour, we will see the requests are being sent to the YouTube API.
When you reload the page again, there will be no requests.
That’s it. Now, you know how to adjust the YouTube API cache time in the WordPress JetBlog plugin using simple filters.







