Let's learn how we can implement simple caching for our plugins. Caching is done in order to lessen the strain on the server and provide faster loading time for the user. This is especially true for blogs with large archives.
Add the variable to store the cache file path. We will use WordPress
wp-content
folder:// name for our options in the DB plugin output, cachingarchives cache, creatingvar $db_option = 'SnazzyArchives_Options'; // path to store the cache file var $cache_path; // Initialize the plugin function SnazzyArchives() { $this->plugin_url = trailingslashit( WP_PLUGIN_URL.'/'. dirname( plugin_basename(__FILE__) ); $this->cache_path = ABSPATH .'wp-content/';
Next, we want to check if the cached content is present at the beginning of our
display()
function. If it is present, we will simply show that file to the user, skipping the dynamic creation of archives:function display() { global $wpdb; // try to retrieve...