Why this matters
The production reason.
Repeated custom queries can hit the database on every page view, even when the result changes only a few times per day.
Transients let you cache the computed result and refresh it on a schedule or when content changes.
Use this for popular posts, related products, taxonomy-heavy lists, and dashboard summaries.
$cache_key = 'theme_popular_posts';
$posts = get_transient( $cache_key );
if ( false === $posts ) {
$posts = new WP_Query([
'posts_per_page' => 6,
'meta_key' => 'views',
'orderby' => 'meta_value_num',
]);
set_transient( $cache_key, $posts, HOUR_IN_SECONDS );
}