[WordPress] 外掛分享: Voce Group Keys

首頁外掛目錄 › Voce Group Keys
全新外掛
安裝啟用
尚無評分
4103 天前
最後更新
問題解決
WordPress 2.8+ v1.0.1 上架:2015-01-05

內容簡介

提供使用函數生成用於快取的字串。鍵是根據傳入的名稱和零個或多個群組生成的。提供相同的名稱和群組會返回相同的鍵,直到整個快取被清除或特定群組的快取被清除。

使用方法

$key: 字串
$groups: 字串 | 陣列

<?php
if ( class_exists( 'Voce_Group_Keys' ) ) {

// 獲取在 $groups 群組中的 $key 鍵
voce_get_cache_key( $key, $groups );

// 清除 $groups 鍵
// 如果指定了多個群組,將清除任何指定群組中的鍵
voce_clear_group_cache( $groups );

// 清除所有鍵
voce_clear_all_group_cache();
}

範例一

<?php
if ( class_exists( 'Voce_Group_Keys' ) ) {

// 獲取不帶群組的鍵
echo voce_get_cache_key( 'data' ); // data_4942b011eb

// 獲取單個群組中的鍵
echo voce_get_cache_key( 'data', 'people' ); // data_9915443f5c
echo voce_get_cache_key( 'more-data', 'people' ); // more-data_9915443f5c

// 將返回相同的鍵
echo voce_get_cache_key( 'data', 'people' ); // data_9915443f5c

// 清除 “people” 群組的鍵
voce_clear_group_cache( 'people' );

// 清除了鍵之後,使用該群組的鍵將返回新的鍵
echo voce_get_cache_key( 'data', 'people' ); // data_77j18e728
echo voce_get_cache_key( 'data' ); // data_4942b011eb

}

範例二

<?php
if ( class_exists( 'Voce_Group_Keys' ) ) {

// 使用多個群組設置暫存
echo voce_get_cache_key( 'user-data', 'users' ); // user-data_9915443f5c
echo voce_get_cache_key( 'post-data', 'posts' ); // post-data_85fb002156
echo voce_get_cache_key( 'user-post-data', array( 'posts', 'users' ) ); // user-post-data_4aee2c2c89

// 清除使用 'posts' 群組的鍵
voce_clear_group_cache( 'posts' );

// 新建使用 'posts' 群組的鍵
echo voce_get_cache_key( 'user-data', 'users' ); // user-data_9915443f5c
echo voce_get_cache_key( 'post-data', 'posts' ); // post-data_820dd0dfb0
echo voce_get_cache_key( 'user-post-data', array( 'posts', 'users' ) ); // user-post-data_b7ac93f802

// 群組的順序無關緊要
echo voce_get_cache_key( 'user-post-data', array( 'users', 'posts' ) ); // user-post-data_b7ac93f802

// 清除 'users' 或 'posts' 群組的任何鍵
voce_clear_group_cache( array( 'users', 'posts' ) );

// 清除所有鍵
voce_clear_all_group_cache();
}

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Voce Group Keys」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Gives functions to use to generate strings to use as keys for caching. Keys are generated based on a passed in name and
zero or more groups. Providing the same name and groups will return the same key until the entire cache is cleared
or the cache for a specific group name is cleared.
Usage
$key: STRING
$groups: STRING|ARRAY

延伸相關外掛

文章
Filter
Apply Filters
Mastodon