PluginProbe
Groups – Memberships and Access Control / 1.11.1
Groups – Memberships and Access Control v1.11.1
4.7.1 4.7.0 4.6.0 4.5.0 4.4.0 4.3.0 trunk 1.0.0-beta-1 1.0.0-beta-2 1.0.0-beta-3 1.0.0-beta-3b 1.0.0-beta-3c 1.0.0-beta-3d 1.1.4 1.1.5 1.10.0 1.10.1 1.10.2 1.10.3 1.11.0 1.11.1 1.11.2 1.11.3 1.12.0 1.13.0 All 131 releases
groups / lib / core / class-groups-cache.php

class-groups-cache.php in Groups – Memberships and Access Control 1.11.1, at lib/core/class-groups-cache.php

83 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * class-groups-cache.php
4 *
5 * Copyright (c) "kento" Karim Rahimpur www.itthinx.com
6 *
7 * This code is released under the GNU General Public License.
8 * See COPYRIGHT.txt and LICENSE.txt.
9 *
10 * This code is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * This header and all notices must be kept intact.
16 *
17 * @author Karim Rahimpur
18 * @package groups
19 * @since groups 1.9.0
20 */
21
22 if ( !defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 /**
27 * Cache service.
28 *
29 * Uses cache objects to encapsulate cached data.
30 *
31 * This makes us completely independent from the problems related to
32 * incomplete cache implementations that ignore the $found parameter used
33 * to disambiguate cache misses with wp_cache_get() when false is retrieved.
34 */
35 class Groups_Cache {
36
37 /**
38 * Default cache group.
39 * @var string
40 */
41 const CACHE_GROUP = 'groups';
42
43 /**
44 * Retrieve an entry from cache.
45 *
46 * @param string $key
47 * @param string $group
48 * @return Groups_Cache_Object|null returns a cache object on hit, null on cache miss
49 */
50 public static function get( $key, $group = self::CACHE_GROUP ) {
51 $found = null;
52 $value = wp_cache_get( $key, $group, false, $found );
53 if ( !( $value instanceof Groups_Cache_Object ) ) {
54 $value = null;
55 }
56 return $value;
57 }
58
59 /**
60 * Store an entry in cache.
61 *
62 * @param string $key
63 * @param string $value
64 * @param string $group
65 * @return true if successful, otherwise false
66 */
67 public static function set( $key, $value, $group = self::CACHE_GROUP ) {
68 $object = new Groups_Cache_Object( $key, $value );
69 return wp_cache_set( $key, $object, $group );
70 }
71
72 /**
73 * Delete a cache entry.
74 *
75 * @param string $key
76 * @param string $group
77 * @return true if successful, otherwise false
78 */
79 public static function delete( $key, $group = self::CACHE_GROUP ) {
80 return wp_cache_delete( $key, $group );
81 }
82 }
83