Skip to content

Commit

Permalink
Fixed #411
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed Jan 4, 2017
1 parent c5111c6 commit 9b134eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/phpFastCache/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public static function getChangelog()
ExtendedCacheItemInterface::setModificationDate() *
* Require configuration directive "itemDetailedDate" to be enabled
- 1.1.3
-- Added an additional CacheItemInterface method:
ExtendedCacheItemInterface::getEncodedKey()
- 1.1.2
-- Implemented [de|a]ttaching methods to improve memory management
ExtendedCacheItemPoolInterface::detachItem()
Expand Down
9 changes: 9 additions & 0 deletions src/phpFastCache/Core/Item/ExtendedCacheItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
*/
interface ExtendedCacheItemInterface extends CacheItemInterface, \JsonSerializable
{
/**
* Returns the encoded key for the current cache item.
* Usually as a MD5 hash
*
* @return string
* The encoded key string for this cache item.
*/
public function getEncodedKey();

/**
* @return mixed
*/
Expand Down
8 changes: 8 additions & 0 deletions src/phpFastCache/Core/Item/ItemExtendedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ trait ItemExtendedTrait
*/
protected $eventManager;

/**
* @return string
*/
public function getEncodedKey()
{
return md5($this->getKey());
}

/**
* @return mixed
*/
Expand Down
15 changes: 3 additions & 12 deletions src/phpFastCache/Drivers/Ssdb/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,7 @@ protected function driverWrite(CacheItemInterface $item)
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
/* if (isset($this->config[ 'skipExisting' ]) && $this->config[ 'skipExisting' ] == true) {
$x = $this->instance->get($item->getKey());
if ($x === false) {
return false;
} elseif (!is_null($x)) {
return true;
}
}*/

return $this->instance->setx($item->getKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl());
return $this->instance->setx($item->getEncodedKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
Expand All @@ -98,7 +89,7 @@ protected function driverWrite(CacheItemInterface $item)
*/
protected function driverRead(CacheItemInterface $item)
{
$val = $this->instance->get($item->getKey());
$val = $this->instance->get($item->getEncodedKey());
if ($val == false) {
return null;
} else {
Expand All @@ -117,7 +108,7 @@ protected function driverDelete(CacheItemInterface $item)
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return $this->instance->del($item->get());
return $this->instance->del($item->getEncodedKey());
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
Expand Down

0 comments on commit 9b134eb

Please sign in to comment.