Skip to content

Commit 8ae3042

Browse files
authored
Make sure we can start using this TaggingPSRItem without dropping all existing data. (#89)
* Make sure we can start using this TaggingPSRItem without dropping all existing data.
1 parent 2254983 commit 8ae3042

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

55
## UNRELEASED
6+
## 0.4.3
7+
8+
### Fixed
9+
10+
* Do not lose the data when you start using the `TaggablePSR6PoolAdapter`
611

712
## 0.4.2
813

TaggablePSR6ItemAdapter.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ public function get()
8282
{
8383
$rawItem = $this->cacheItem->get();
8484

85-
if (is_array($rawItem) && isset($rawItem['value'])) {
85+
// If it is a cache item we created
86+
if ($this->isItemCreatedHere($rawItem)) {
8687
return $rawItem['value'];
8788
}
89+
90+
// This is an item stored before we used this fake cache
91+
return $rawItem;
8892
}
8993

9094
/**
@@ -178,12 +182,24 @@ private function initializeTags()
178182
if ($this->cacheItem->isHit()) {
179183
$rawItem = $this->cacheItem->get();
180184

181-
if (is_array($rawItem) && isset($rawItem['tags'])) {
185+
if ($this->isItemCreatedHere($rawItem)) {
182186
$this->tags = $rawItem['tags'];
183187
}
184188
}
185189

186190
$this->initialized = true;
187191
}
188192
}
193+
194+
/**
195+
* Verify that the raw data is a cache item created by this class.
196+
*
197+
* @param mixed $rawItem
198+
*
199+
* @return bool
200+
*/
201+
private function isItemCreatedHere($rawItem)
202+
{
203+
return is_array($rawItem) && isset($rawItem['value']) && isset($rawItem['tags']) && count($rawItem) === 2;
204+
}
189205
}

0 commit comments

Comments
 (0)