Home > Backend Development > PHP Tutorial > wp_cache_set and wp_cache_get_PHP tutorial

wp_cache_set and wp_cache_get_PHP tutorial

WBOY
Release: 2016-07-13 17:17:06
Original
1072 people have browsed it

 

<span function</span> wp_cache_set( <span $key</span>, <span $data</span>, <span $group</span> = '', <span $expire</span> = 0<span  ) {
    </span><span global</span> <span $wp_object_cache</span><span ;
 
    </span><span return</span> <span $wp_object_cache</span>-&gt;set( <span $key</span>, <span $data</span>, <span $group</span>, (int) <span $expire</span><span  );
}</span>
Copy after login

<span function</span> wp_cache_get( <span $key</span>, <span $group</span> = '', <span $force</span> = <span false</span>, &amp;<span $found</span> = <span null</span><span  ) {
    </span><span global</span> <span $wp_object_cache</span><span ;
 
    </span><span return</span> <span $wp_object_cache</span>-&gt;get( <span $key</span>, <span $group</span>, <span $force</span>, <span $found</span><span  );
}</span>
Copy after login


=->ID,,'related_posts',3600);

<span global</span> <span $post</span><span ;
</span><span $related_posts_data</span> = wp_cache_get(<span $post</span>-&gt;ID,'related_posts'<span );
</span><span if</span>(<span false</span> === <span $related_posts_data</span><span ){
    </span><span $related_posts_data</span> =<span  wp_get_related_posts();
    wp_cache_set(</span><span $post</span>-&gt;ID,<span $related_posts_data</span>,'related_posts',3600<span );
}
</span><span echo</span> <span $related_posts_data</span>;
Copy after login

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/626629.htmlTechArticlewp_cache_set( , , = '', = 0 -gt;set( , , , (int) wp_cache_get( , = '', = , amp; = -gt;get( , , , = -gt;ID, ,'related_posts',3600); = wp_cache_get( -gt;ID,'related_posts' ( === = -g...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template