PluginProbe
Parse.ly / 3.2.0
Parse.ly v3.2.0
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / RemoteAPI / class-wordpress-cache.php

class-wordpress-cache.php in Parse.ly 3.2.0, at src/RemoteAPI/class-wordpress-cache.php

69 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Parsely Remote API Adapter for the WordPress Object Cache
4 *
5 * @package Parsely
6 * @since 3.2.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\RemoteAPI;
12
13 use WP_Object_Cache;
14
15 /**
16 * Remote API Adapter for the WordPress Object Cache.
17 */
18 class WordPress_Cache implements Cache {
19 /**
20 * The WordPress Object Cache.
21 *
22 * @var WP_Object_Cache
23 */
24 private $cache;
25
26 /**
27 * Constructor.
28 *
29 * @param WP_Object_Cache $cache A class that's compatible with the Cache Interface.
30 */
31 public function __construct( WP_Object_Cache $cache ) {
32 $this->cache = $cache;
33 }
34
35 /**
36 * Retrieves the cache contents from the cache by key and group.
37 *
38 * @since 3.2.0
39 *
40 * @param int|string $key The key under which the cache contents are stored.
41 * @param string $group Optional. Where the cache contents are grouped. Default empty.
42 * @param bool $force Optional. Whether to force an update of the local cache
43 * from the persistent cache. Default false.
44 * @param bool $found Optional. Whether the key was found in the cache (passed by reference).
45 * Disambiguates a return of false, a storable value. Default null.
46 * @return mixed|false The cache contents on success, false on failure to retrieve contents.
47 */
48 public function get( $key, string $group = '', bool $force = false, bool $found = null ) {
49 return $this->cache->get( $key, $group, $force, $found );
50 }
51
52 /**
53 * Saves the data to the cache.
54 *
55 * @since 3.2.0
56 *
57 * @param int|string $key The cache key to use for retrieval later.
58 * @param mixed $data The contents to store in the cache.
59 * @param string $group Optional. Where to group the cache contents. Enables the same key
60 * to be used across groups. Default empty.
61 * @param int $expire Optional. When to expire the cache contents, in seconds.
62 * Default 0 (no expiration).
63 * @return bool True on success, false on failure.
64 */
65 public function set( $key, $data, string $group = '', int $expire = 0 ): bool {
66 return $this->cache->set( $key, $data, $group, $expire );
67 }
68 }
69