set() публичный Метод

The cache contents is grouped by the $group parameter followed by the $key. This allows for duplicate ids in unique groups. Therefore, naming of the group should be used with care and should follow normal function naming guidelines outside of core WordPress usage. The $expire parameter is not used, because the cache will automatically expire for each time a page is accessed and PHP finishes. The method is more for cache plugins which use files.
public set ( integer | string $key, mixed $data, string $group = 'default', integer $expire ) : boolean
$key integer | string What to call the contents in the cache
$data mixed The contents to store in the cache
$group string Where to group the cache contents
$expire integer TTL for the data, in seconds
Результат boolean Always returns true
Пример #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'));
 }
Пример #2
0
 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'));
 }
Пример #3
0
 /**
  * Put value into object cache.
  *
  * @param string $key
  * @param string $value
  * @param bool   $lock
  *
  * @return mixed
  */
 public function put($key, $value, $lock = false)
 {
     return $this->cache->set($key, ['content' => $value, 'modified' => time()], 'bladerunner');
 }