Cache - Dynamic Shortcodes

Utilize the Cache Dynamic Shortcode for optimal data caching in WordPress to improve site performance and user experience.

Updated over a week ago

The Cache Dynamic Shortcode offers a method for temporary data storage, enabling the caching of content within WordPress. Its main benefit is to boost performance by reducing database load and cutting down on page loading times.

This shortcode allows for the caching of other Dynamic Shortcodes, and it simplifies the process of storing, fetching, and erasing cached entries with customizable expiration periods.

Syntax

The syntax for implementing the Cache Dynamic Shortcode is as follows:

  • For creating/updating cached data: {cache:<key> <value>@<key_arguments>}

  • For retrieving cached data: {get-cache:<key>}

  • For deleting cached data {delete-cache:<key>}

Key Arguments

  • expiration (alias exp): Determines how long the data should be kept cached, specified in natural language like "30 minutes", "1 day" or "2 weeks".

Examples

  1. Caching Data: {cache:current_weather "Sunny"@expiration="30 minutes"} This example caches the string "Sunny" with the key current_weather for 30 minutes.

  2. Retrieving Cached Data: {get-cache:current_weather} Retrieves whatever data is stored under the current_weather cache key.

  3. Caching with Default Expiration: {cache:website_stats "1500 visits"} Stores "1500 visits" under website_stats with a standard expiration time.

  4. Dynamic Caching with ACF: {cache:user_bio {acf:user_bio_field}} Caches the output of an ACF field user_bio_field under the cache key user_bio.

Did this answer your question?