-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tagging bugfix and updated tests to ^0.9
- Loading branch information
Showing
2 changed files
with
26 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
* @author Magnus Nordlander | ||
*/ | ||
class MongoDBCachePool extends AbstractCachePool | ||
{ | ||
|
@@ -34,6 +35,13 @@ public function __construct(Collection $collection) | |
$this->collection = $collection; | ||
} | ||
|
||
/** | ||
* @param Manager $manager | ||
* @param string $database | ||
* @param string $collection | ||
* | ||
* @return Collection | ||
*/ | ||
public static function createCollection(Manager $manager, $database, $collection) | ||
{ | ||
$collection = new Collection($manager, $database, $collection); | ||
|
@@ -42,37 +50,49 @@ public static function createCollection(Manager $manager, $database, $collection | |
return $collection; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function fetchObjectFromCache($key) | ||
{ | ||
$object = $this->collection->findOne(['_id' => $key]); | ||
|
||
if (!$object || !isset($object->data)) { | ||
return [false, null]; | ||
return [false, null, []]; | ||
} | ||
|
||
if (isset($object->expiresAt)) { | ||
if ($object->expiresAt < time()) { | ||
return [false, null]; | ||
return [false, null, []]; | ||
} | ||
} | ||
|
||
return [true, unserialize($object->data)]; | ||
return [true, unserialize($object->data), []]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function clearAllObjectsFromCache() | ||
{ | ||
$this->collection->deleteMany([]); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function clearOneObjectFromCache($key) | ||
{ | ||
$this->collection->deleteOne(['_id' => $key]); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function storeItemInCache(CacheItemInterface $item, $ttl) | ||
{ | ||
$object = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters