Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
banderon authored Feb 28, 2019
1 parent bd17950 commit 6c37d5a
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Voce Group Keys
Contributors: banderon
Tags: cache, group, keys
Requires at least: 2.8
Tested up to: 4.0
Stable tag: 1.0.1
Tested up to: 5.0.1
Stable tag: 1.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -27,11 +27,12 @@ if( ! class_exists( 'Voce_Group_Keys' ) ) {
## Usage

$key: STRING
$groups: STRING|ARRAY
$groups: STRING|ARRAY (optional)
$limit_key: BOOL (optional)

```php
// Get a key for $key that is in the $groups group(s)
voce_get_cache_key( $key, $groups );
// Get a key for $key that is in the $groups group(s) maybe limited in length by $limit_key
voce_get_cache_key( $key, $groups, $limit_key );

// Clear the keys for $groups
// If multiple groups are specified, keys in any of the specified groups will be cleared
Expand All @@ -41,22 +42,25 @@ voce_clear_group_cache( $groups );
voce_clear_all_group_cache();
```

By default, `$limit_key` is set to `true`. This will truncate the generated key to fit into the `column_name` column in
the options table for your version of WP.

#### Example 1

```php
<?php
// Get keys in a single group
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_dcc0c6f0427d745f94c07d89cda83936
echo voce_get_cache_key( 'more-data', 'people' ); // more-data_dcc0c6f0427d745f94c07d89cda83936

// The same key will be returned
echo voce_get_cache_key( 'data', 'people' ); // data_9915443f5c
echo voce_get_cache_key( 'data', 'people' ); // data_dcc0c6f0427d745f94c07d89cda83936

// Clear keys in the 'people' group
voce_clear_group_cache( 'people' );

// After clearing keys, a new key is returned
echo voce_get_cache_key( 'data', 'people' ); // data_77j18e728
echo voce_get_cache_key( 'data', 'people' ); // data_65bf7e23ff9c9291bd235c7ae58d8de9
?>
```

Expand All @@ -65,17 +69,17 @@ echo voce_get_cache_key( 'data', 'people' ); // data_77j18e728
```php
<?php
// Set transients using multiple groups
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
echo voce_get_cache_key( 'user-data', 'users' ); // user-data_084cdd52c35c861257675e4e95d92d22
echo voce_get_cache_key( 'post-data', 'posts' ); // post-data_b1b9905dc4833fc7f3196101030979d6
echo voce_get_cache_key( 'user-post-data', array( 'posts', 'users' ) ); // user-post-data_c86d148164b80e3efb8cafe2b7466367

// Clear any keys in the 'posts' group
voce_clear_group_cache( 'posts' );

// New keys generated for anything in the 'posts' group
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-data', 'users' ); // user-data_084cdd52c35c861257675e4e95d92d22
echo voce_get_cache_key( 'post-data', 'posts' ); // post-data_5b56d4151cb9b1cb896337f0b8b44059
echo voce_get_cache_key( 'user-post-data', array( 'posts', 'users' ) ); // user-post-data_b08629bf2ca13a4e56429251a372005a

// Clear any keys in either the 'users' or 'posts' groups
voce_clear_group_cache( array( 'users', 'posts' ) );
Expand All @@ -86,6 +90,9 @@ voce_clear_all_group_cache();
```

## Version History
**1.1**
*Allow specifying whether to limit the length of the generated key based on the column size of WP's `option_name` column.

**1.0.1**
*Bug fix: added slight delay when saving new keys to avoid collisions

Expand Down

0 comments on commit 6c37d5a

Please sign in to comment.