get() public method

The contents will be first attempted to be retrieved by searching by the key in the cache group. If the cache is hit (success) then the contents are returned. On failure, the number of cache misses will be incremented.
public get ( integer | string $key, string $group = 'default', string $force = false, boolean &$found = null ) : boolean | mixed
$key integer | string What the contents in the cache are called
$group string Where the cache contents are grouped
$force string Whether to force a refetch rather than relying on the local cache (default is false)
$found boolean Optional. Whether the key was found in the cache. Disambiguates a return of false, a storable value. Passed by reference. Default null.
return boolean | mixed False on failure to retrieve contents or the cache contents on success
Beispiel #1
0
 public function test_redis_bad_authentication()
 {
     global $redis_server;
     if (!class_exists('Redis')) {
         $this->markTestSkipped('PHPRedis extension not available.');
     }
     $redis_server['host'] = '127.0.0.1';
     $redis_server['port'] = 9999;
     $redis_server['auth'] = 'foobar';
     $cache = new WP_Object_Cache();
     $this->assertEquals('WP Redis: Redis server went away', $cache->last_triggered_error);
     $this->assertFalse($cache->is_redis_connected);
     // Fails back to the internal object cache
     $cache->set('foo', 'bar');
     $this->assertEquals('bar', $cache->get('foo'));
 }
 public function test_redis_connect_custom_database()
 {
     global $redis_server;
     if (!class_exists('Redis')) {
         $this->markTestSkipped('PHPRedis extension not available.');
     }
     $redis_server['database'] = 2;
     $second_cache = new WP_Object_Cache();
     $this->cache->set('foo', 'bar');
     $this->assertEquals('bar', $this->cache->get('foo'));
     $this->assertFalse($second_cache->get('foo'));
     $second_cache->set('foo', 'apple');
     $this->assertEquals('apple', $second_cache->get('foo'));
     $this->assertEquals('bar', $this->cache->get('foo'));
 }
Beispiel #3
0
 /**
  * Get last modified value by key.
  *
  * @param string $key
  *
  * @return mixed
  */
 public function lastModified($key)
 {
     $value = $this->cache->get($key, 'bladerunner');
     return $value ? $value['modified'] : null;
 }