Skip to content

Commit 9b134eb

Browse files
committed
Fixed #411
1 parent c5111c6 commit 9b134eb

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

src/phpFastCache/Api.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public static function getChangelog()
7272
ExtendedCacheItemInterface::setModificationDate() *
7373
* Require configuration directive "itemDetailedDate" to be enabled
7474
75+
- 1.1.3
76+
-- Added an additional CacheItemInterface method:
77+
ExtendedCacheItemInterface::getEncodedKey()
78+
7579
- 1.1.2
7680
-- Implemented [de|a]ttaching methods to improve memory management
7781
ExtendedCacheItemPoolInterface::detachItem()

src/phpFastCache/Core/Item/ExtendedCacheItemInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
*/
2525
interface ExtendedCacheItemInterface extends CacheItemInterface, \JsonSerializable
2626
{
27+
/**
28+
* Returns the encoded key for the current cache item.
29+
* Usually as a MD5 hash
30+
*
31+
* @return string
32+
* The encoded key string for this cache item.
33+
*/
34+
public function getEncodedKey();
35+
2736
/**
2837
* @return mixed
2938
*/

src/phpFastCache/Core/Item/ItemExtendedTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ trait ItemExtendedTrait
3333
*/
3434
protected $eventManager;
3535

36+
/**
37+
* @return string
38+
*/
39+
public function getEncodedKey()
40+
{
41+
return md5($this->getKey());
42+
}
43+
3644
/**
3745
* @return mixed
3846
*/

src/phpFastCache/Drivers/Ssdb/Driver.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,7 @@ protected function driverWrite(CacheItemInterface $item)
7777
* Check for Cross-Driver type confusion
7878
*/
7979
if ($item instanceof Item) {
80-
/* if (isset($this->config[ 'skipExisting' ]) && $this->config[ 'skipExisting' ] == true) {
81-
$x = $this->instance->get($item->getKey());
82-
if ($x === false) {
83-
return false;
84-
} elseif (!is_null($x)) {
85-
return true;
86-
}
87-
}*/
88-
89-
return $this->instance->setx($item->getKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl());
80+
return $this->instance->setx($item->getEncodedKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl());
9081
} else {
9182
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
9283
}
@@ -98,7 +89,7 @@ protected function driverWrite(CacheItemInterface $item)
9889
*/
9990
protected function driverRead(CacheItemInterface $item)
10091
{
101-
$val = $this->instance->get($item->getKey());
92+
$val = $this->instance->get($item->getEncodedKey());
10293
if ($val == false) {
10394
return null;
10495
} else {
@@ -117,7 +108,7 @@ protected function driverDelete(CacheItemInterface $item)
117108
* Check for Cross-Driver type confusion
118109
*/
119110
if ($item instanceof Item) {
120-
return $this->instance->del($item->get());
111+
return $this->instance->del($item->getEncodedKey());
121112
} else {
122113
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
123114
}

0 commit comments

Comments
 (0)