站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
Function Reference/WP Cache
”
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
Fludlen
(
讨论
|
贡献
)
2008年7月23日 (三) 13:56的版本
(
差异
)
←上一版本
|
最后版本
(
差异
) |
下一版本→
(
差异
)
跳转至:
导航
、
搜索
警告:您正在编辑的是本页面的旧版本。
如果您发布该更改,该版本后的所有更改都会丢失。
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
==Role of WP_Cache== == WP_Cache角色== <tt>WP_Object_Cache</tt> is WordPress' class for caching data which may be computationally intensive to regenerate dynamically on every page load. It's defined in <tt>wp-includes/cache.php</tt>. <tt>WP_Object_Cache</tt> 是WordPress' class,是用来储存数据的,这些数据在每次网页载入的时候,可能很难计算。WP_Cache定义在<tt>wp-includes/cache.php</tt>。 Do not use the class directly in your code when writing plugins, but use the wp_cache functions listed here. 编写插件的时候,不要直接地将class用在你的代码中,使用这里列出的wp_cache函数。 Caching to file to store the information across page loads is not enabled by default - this can be enabled by adding <tt>define('ENABLE_CACHE', true);</tt> to your wp-config.php file. 存储文件,在网页载入时,储存信息,这个功能并不是默认的-通过向wp-config.php文件添加<tt>define('ENABLE_CACHE', true);</tt>可以添加这个功能。 Within a single page loading caching does still occur so as to reduce the number of database queries as much as possible 单一网页载入时,不会出现高速缓存,这样可以尽量地减少数据库查询 ==wp_cache functions== ==wp_cache 函数== Almost all of these functions take a: 几乎所有的这些函数都有一个: * key: the key to indicate the value *key:暗示参数值的关键词 * $data: the value you want to store * $data:你想要储存的参数值 * flag: optional: this is a way of grouping your cache data. If you use a flag, your data will be stored in a subdirectory of your cache directory * flag: optional:这是组合缓存数据的一种方式。如果是使用标记,数据就会储存在高速缓存目录的子目录中 * expire: number of seconds (by default 900) * expire:秒数(默认为900秒) <pre>wp_cache_add($key, $data, $flag = '', $expire = 0)</pre> This function first checks if there is a cached object on the given $key. If not, then it is saved, otherwise returns false. <pre>wp_cache_add($key, $data, $flag = '', $expire = 0)</pre> 这个函数首先检查给出的$key是否有cached object。如果没有,就会保存,否则就会返回错误的。 <pre>wp_cache_delete($id, $flag = '') </pre> Clears a given file. <pre>wp_cache_delete($id, $flag = '') </pre> 清除给定的文件。 <pre>wp_cache_get($id, $flag = '')</pre> Gives back the value of the cached object if it did not expired. Otherwise gives back false. <pre>wp_cache_get($id, $flag = '')</pre> 如果储存的object没有期满,返回这个object的参数值。否则返回错误的。 <pre>wp_cache_replace($key, $data, $flag = '', $expire = 0)</pre> Replaces the given cache if it exists, returns false otherwise. <pre>wp_cache_replace($key, $data, $flag = '', $expire = 0)</pre> 如果存在高速缓存,取代给定的高速缓存,否则返回错误的。 <pre>wp_cache_set($key, $data, $flag = '', $expire = 0)</pre> Sets the value of the cache object. If the object already exists, then it will be overwritten, if the object does not exists it will be created. <pre>wp_cache_set($key, $data, $flag = '', $expire = 0)</pre> 设置cache object的参数值。如果object已经存在,就会被覆盖,如果object不存在,会得到创建。 <pre>wp_cache_init() </pre> <pre>wp_cache_init() </pre> Initializes a new cache object. This function is called by Wordpress at initialization if cacheing is enabled. 初始化新的cache object。如果高速缓存正在运行,进行初始化过程时,WordPress会调用这个函数。 <pre>wp_cache_flush() </pre> Clears all the cache files. <pre>wp_cache_flush() </pre> 清除所有高速缓存文件。 <pre>wp_cache_close()</pre> Saves the cached object. This function is called by Wordpress at the shutdown action hook. 保存cached object。在shutdown action hook时,WordPress调用了这个函数。 == Examples == == 例子 == You can use WP_Object_Cache and Snoopy to cache offsite includes: 你可以使用WP_Object_Cache 和Snoopy高速缓存offsite includes: $news = wp_cache_get('news'); if($news == false) { $snoopy = new Snoopy; $snoopy->fetch('http://example.com/news/'); $news = $snoopy->results; wp_cache_set('news', $news); } echo $news; $news = wp_cache_get('news'); if($news == false) { $snoopy = new Snoopy; $snoopy->fetch('http://example.com/news/'); $news = $snoopy->results; wp_cache_set('news', $news); } echo $news; == Additional Resources == == 额外的资源 == * '''Dougal Campbell''' wrote a short guide on how to use the Wordpress Cache object from within your own plugins : [http://dougal.gunters.org/blog/2006/07/21/using-the-wordpress-object-cache Using the Wordpress Object Cache] * '''Dougal Campbell'''编写一个简短的指南,关于怎样使用插件中的WordPress Cache object: * '''Peter Westwood''' has a plugin to help people analyse the behaviour of the cache, provides the administrator with a quick overview of how the cache is performming and what queries are cached : [http://blog.ftwr.co.uk/wordpress/wp-cache-inspect/ WP Cache Inspect] * '''Peter Westwood'''拥有一个插件能够帮助人们分享cache,能使管理员快速浏览cache是怎样运行的以及哪个查询得到了cache: [http://blog.ftwr.co.uk/wordpress/wp-cache-inspect/ WP Cache Inspect]
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)