In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use WordPress object cache, the article is very detailed, has a certain reference value, interested friends must read it!
To understand WordPress optimization in depth, you must first understand the WordPress object caching mechanism.
WordPress object caching mechanisms and server settings
WordPress Object Cache (WordPress Object Cache) is WordPress caching mechanism, its main function is to be responsible for query or calculation results according to Key-Value such a way (WordPress also supports the division and avoid cached content conflicts according to the Group) stored in the object, the next time the same operation, you can directly extract data from this object, do not repeat to the database or other external sites to obtain data.
WordPress Object Cache has a lot to do with server settings. If the Memcached memory cache is enabled, the object is directly stored in memory. Before the data expires, the data is read directly from memory again. This is very efficient and fast.
If the server does not support memory caching, it can only ensure that the same query or operation is not repeated from the database under the current page.
WordPress object caching functions
Using WordPress object caching technology is actually very simple:
Use wp_cache_add() to add data to the cache.
Use wp_cache_set() to set data into cache.
Use wp_cache_get() to read data from cache.
Use wp_cache_delete() to delete data from cache.
These functions involve four parameters:
parameters
$key object key.
$data The value to be stored.
$group, optional parameter, used to group cache objects on the line.
$expire expiration time, optional parameter, if it is default cache, this parameter is useless, if it is memory cache, it is the time to set cache, unit is seconds, default is 0 (0 means never, will not automatically expire).
Using WordPress Object Cache
Here is an example of how to use WordPress object caching using the WordPress plugin I am about to update:
We know that WordPress related article plug-in is through tag and classification to obtain related articles, the more the same tag and classification, the stronger the correlation, so you need to make multiple table joint query to obtain related articles, so the efficiency is actually relatively poor. However, an article's related articles will not change for a period of time, so we can use WordPress object cache to accelerate related articles.
The following is an example of writing related article data to cache, using the current post_id as key, related_posts as group, cache time is one hour, that is, 3600 seconds.
global $post;$related_posts_data = wp_get_related_posts();wp_cache_set($post->ID,$related_posts_data,'related_posts',3600);
The above only stores the data into the cache object. When we display related articles, we must call this object cache to use. First check whether there is already a cache. If the information you want is not in the cache, or it has expired. wp_cache_get() will return false, if so, you will have to retrieve this information from the database. Otherwise, the information in the cache is returned.
global $post;$related_posts_data = wp_cache_get($post->ID,'related_posts');if(false === $related_posts_data){$related_posts_data = wp_get_related_posts();wp_cache_set($post->ID,$related_posts_data,'related_posts',3600);}echo $related_posts_data;
Because the settings are set for an hour, the data of related articles will be invalid. Generally, there is no need to update the cache. If you change the settings in the background, you need to clean the cache immediately. You can use wp_cache_delete to clean it up:
wp_cacache_delete($post->ID,'related_posts');
WPJAM Basic plug-in has integrated Memcached. After downloading WPJAM Basic, copy the object-cache.php file under wpjam-basic/template/directory to wp-content directory.
That's all about how to use WordPress object caching, thanks for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.