Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Added capability 'lock-on-expire' #80

Merged
merged 3 commits into from
Apr 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions doc/book/storage/adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ Capability | Value
`ttlPrecision` | 1
`useRequestTime` | value of `apc.use_request_time` from `php.ini`
`expiredRead` | `false`
`lockOnExpire` | 0
`maxKeyLength` | 5182
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`
Expand Down Expand Up @@ -632,6 +633,7 @@ Capability | Value
`ttlPrecision` | 1
`useRequestTime` | `false`
`expiredRead` | `true`
`lockOnExpire` | 0
`maxKeyLength` | 251
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`
Expand Down Expand Up @@ -677,6 +679,7 @@ Capability | Value
`ttlPrecision` | 1
`useRequestTime` | `false`
`expiredRead` | `false`
`lockOnExpire` | 0
`maxKeyLength` | 255
`namespaceIsPrefix` | `true`
`namespaceSeparator` | none
Expand Down Expand Up @@ -710,6 +713,7 @@ Capability | Value
`ttlPrecision` | 1
`useRequestTime` | `false`
`expiredRead` | `false`
`lockOnExpire` | 0
`maxKeyLength` | 255
`namespaceIsPrefix` | `true`
`namespaceSeparator` | none
Expand Down Expand Up @@ -760,6 +764,7 @@ Capability | Value
`ttlPrecision` | 0.05
`useRequestTime` | `false`
`expiredRead` | `true`
`lockOnExpire` | 0
`maxKeyLength` | 0
`namespaceIsPrefix` | `false`

Expand Down Expand Up @@ -797,17 +802,18 @@ This adapter implements the following interfaces:
### Capabilities

Capability Value
supportedDatatypes null, boolean, integer, double, string, array
supportedMetadata _id
minTtl 0
maxTtl 0
staticTtl true
ttlPrecision 1
useRequestTime false
expiredRead false
maxKeyLength 255
namespaceIsPrefix true
namespaceSeparator <Option value of namespace_separator>
`supportedDatatypes` | `null`, `boolean`, `integer`, `double`, `string`, `array`
`supportedMetadata` | _id
`minTtl` | 0
`maxTtl` | 0
`staticTtl` | `true`
`ttlPrecision` | 1
`useRequestTime` | `false`
`expiredRead` | `false`
`lockOnExpire` | 0
`maxKeyLength` | 255
`namespaceIsPrefix` | `true`
`namespaceSeparator` | <Option value of namespace_separator>

### Adapter specific options

Expand Down Expand Up @@ -850,6 +856,7 @@ Capability | Value
`ttlPrecision` | 1
`useRequestTime` | `apc.use_request_time` `php.ini` value.
`expiredRead` | `false`
`lockOnExpire` | 0
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`

Expand Down Expand Up @@ -886,6 +893,7 @@ Capability | Value
`ttlPrecision` | 1
`useRequestTime` | `true`
`expiredRead` | `false`
`lockOnExpire` | 0
`maxKeyLength` | 5182
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`
Expand Down Expand Up @@ -925,6 +933,7 @@ Capability | Value
`ttlPrecision` | 1
`useRequestTime` | `false`
`expiredRead` | `false`
`lockOnExpire` | if 'zend_datacache.lock_on_expire' is enabled 120 else 0
`namespaceIsPrefix` | `true`
`namespaceSeparator` | `::`

Expand Down Expand Up @@ -953,6 +962,7 @@ Capability | Value
`ttlPrecision` | 1
`useRequestTime` | `false`
`expiredRead` | `false`
`lockOnExpire` | if 'zend_datacache.lock_on_expire' is enabled 120 else 0
`namespaceIsPrefix` | `true`
`namespaceSeparator` | `::`

Expand Down
24 changes: 24 additions & 0 deletions doc/book/storage/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ class Capabilities
*/
public function setExpiredRead(stdClass $marker, $flag);

/**
* Get "lock-on-expire" support in seconds.
*
* @return int 0 = Expired items will never be retrieved
* >0 = Time in seconds an expired item could be retrieved
* -1 = Expired items could be retrieved forever
*/
public function getLockOnExpire()
{
return $this->getCapability('lockOnExpire', 0);
}

/**
* Set "lock-on-expire" support in seconds.
*
* @param stdClass $marker
* @param int $timeout
* @return Capabilities Fluent interface
*/
public function setLockOnExpire(stdClass $marker, $timeout)
{
return $this->setCapability($marker, 'lockOnExpire', (int) $timeout);
}

/**
* Get maximum key lenth
*
Expand Down
1 change: 1 addition & 0 deletions src/Storage/Adapter/AbstractZendServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ protected function internalGetCapabilities()
'ttlPrecision' => 1,
'useRequestTime' => false,
'expiredRead' => false,
'lockOnExpire' => ini_get('zend_datacache.lock_on_expire') ? 120 : 0,
'maxKeyLength' => 0,
'namespaceIsPrefix' => true,
'namespaceSeparator' => self::NAMESPACE_SEPARATOR,
Expand Down
38 changes: 38 additions & 0 deletions src/Storage/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ class Capabilities
*/
protected $expiredRead;

/**
* "lock-on-expire" support in seconds.
*
* 0 = Expired items will never be retrieved
* >0 = Time in seconds an expired item could be retrieved
* -1 = Expired items could be retrieved forever
*
* If it's NULL the capability isn't set and the getter
* returns the base capability or the default value.
*
* @var null|bool
*/
protected $lockOnExpire;

/**
* Max. key length
*
Expand Down Expand Up @@ -421,6 +435,30 @@ public function setExpiredRead(stdClass $marker, $flag)
return $this->setCapability($marker, 'expiredRead', (bool) $flag);
}

/**
* Get "lock-on-expire" support in seconds.
*
* @return int 0 = Expired items will never be retrieved
* >0 = Time in seconds an expired item could be retrieved
* -1 = Expired items could be retrieved forever
*/
public function getLockOnExpire()
{
return $this->getCapability('lockOnExpire', 0);
}

/**
* Set "lock-on-expire" support in seconds.
*
* @param stdClass $marker
* @param int $timeout
* @return Capabilities Fluent interface
*/
public function setLockOnExpire(stdClass $marker, $timeout)
{
return $this->setCapability($marker, 'lockOnExpire', (int) $timeout);
}

/**
* Get maximum key lenth
*
Expand Down
16 changes: 14 additions & 2 deletions test/Storage/Adapter/CommonAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function testTtlCapabilities()
$this->assertGreaterThan(0, $capabilities->getTtlPrecision());

$this->assertInternalType('bool', $capabilities->getExpiredRead());
$this->assertInternalType('int', $capabilities->getLockOnExpire());
}

public function testKeyCapabilities()
Expand Down Expand Up @@ -577,8 +578,7 @@ public function testSetAndGetExpiredItem()

$this->assertNull($this->_storage->getItem('key'));

$this->_options->setTtl(0);
if ($capabilities->getExpiredRead()) {
if ($capabilities->getLockOnExpire()) {
$this->assertEquals('value', $this->_storage->getItem('key'));
} else {
$this->assertNull($this->_storage->getItem('key'));
Expand Down Expand Up @@ -640,6 +640,18 @@ public function testSetAndGetExpiredItems()
$this->assertEquals($items, $rs);
} else {
$this->assertEquals($itemsHigh, $rs);

// if 'lock-on-expire' is not supported the low items will be still missing
// if 'lock-on-expire' is supported the low items could be retrieved
$rs = $this->_storage->getItems(array_keys($items));
ksort($rs); // make comparable
if (!$capabilities->getLockOnExpire()) {
$this->assertEquals($itemsHigh, $rs);
} else {
$itemsExpected = array_merge($itemsLow, $itemsHigh);
ksort($itemsExpected); // make comparable
$this->assertEquals($itemsExpected, $rs);
}
}
}

Expand Down