/** * Set options. * * @param array|Traversable|Adapter\AdapterOptions $options * @return StorageInterface Fluent interface */ public function setOptions($options) { if ($this->options !== $options) { if (!$options instanceof AdapterOptions) { $options = new AdapterOptions($options); } if ($this->options) { $this->options->setAdapter(null); } $options->setAdapter($this); $this->options = $options; } return $this; }
/** * Set namespace. * * The option Memcached::OPT_PREFIX_KEY will be used as the namespace. * It can't be longer than 128 characters. * * @see AdapterOptions::setNamespace() * @see MemcachedOptions::setPrefixKey() */ public function setNamespace($namespace) { $namespace = (string) $namespace; if (128 < strlen($namespace)) { throw new Exception\InvalidArgumentException(sprintf('%s expects a prefix key of no longer than 128 characters', __METHOD__)); } return parent::setNamespace($namespace); }
public function testSetItemAndSetItemsCallSaveWithTtl() { $ttl = rand(); $provider = $this->getMock('Doctrine\\Common\\Cache\\ArrayCache'); $provider->expects($this->exactly(4))->method('save')->with($this->anything(), $this->anything(), $ttl); $this->storage = new DoctrineCacheStorage($this->options, $provider); $this->options->setTtl($ttl); $this->storage->setItem('key', 'value'); $items = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'); $this->storage->setItems($items); }
public function testClearExpired() { if (!$this->_storage instanceof ClearExpiredInterface) { $this->markTestSkipped("Storage doesn't implement ClearExpiredInterface"); } $capabilities = $this->_storage->getCapabilities(); $ttl = $capabilities->getTtlPrecision(); $this->_options->setTtl($ttl); $this->waitForFullSecond(); $this->assertTrue($this->_storage->setItem('key1', 'value1')); // wait until the first item expired $wait = $ttl + $capabilities->getTtlPrecision(); usleep($wait * 2000000); $this->assertTrue($this->_storage->setItem('key2', 'value2')); $this->assertTrue($this->_storage->clearExpired()); if ($capabilities->getUseRequestTime()) { $this->assertTrue($this->_storage->hasItem('key1')); } else { $this->assertFalse($this->_storage->hasItem('key1', ['ttl' => 0])); } $this->assertTrue($this->_storage->hasItem('key2')); }
/** * Set options. * * @param array|Traversable|AdapterOptions $options * @return AbstractAdapter * @see getOptions() */ public function setOptions($options) { if ($this->options !== $options) { if (!$options instanceof AdapterOptions) { $options = new AdapterOptions($options); } if ($this->options) { $this->options->setAdapter(null); } $options->setAdapter($this); $this->options = $options; $event = new Event('option', $this, new ArrayObject($options->toArray())); $this->getEventManager()->trigger($event); } return $this; }
public function testTouchItemsReturnsGivenKeysIfNonWritable() { $this->_options->setWritable(false); $this->assertSame(array('key'), $this->_storage->touchItems(array('key'))); }
/** * Constructor * * @param array|Traversable|null $options * @return FilesystemOptions * @throws Exception\InvalidArgumentException */ public function __construct($options = null) { // disable file/directory permissions by default on windows systems if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $this->filePermission = false; $this->dirPermission = false; } parent::__construct($options); }