You are here

public function MemcachedDriver::add in Memcache API and Integration 8.2

Add an item to Memcache if it doesn't exist already.

Parameters

string $key: The key to add.

mixed $value: The value to add.

int $expire: The expiration time in seconds.

Return value

bool TRUE on success or FALSE on failure.

Overrides DrupalMemcacheInterface::add

File

src/Driver/MemcachedDriver.php, line 40

Class

MemcachedDriver
Class MemcachedDriver.

Namespace

Drupal\memcache\Driver

Code

public function add($key, $value, $expire = 0) {
  $collect_stats = $this
    ->statsInit();
  $full_key = $this
    ->key($key);
  $result = $this->memcache
    ->add($full_key, $value, $expire);
  if ($collect_stats) {
    $this
      ->statsWrite('add', 'cache', [
      $full_key => (int) $result,
    ]);
  }
  return $result;
}