Skip to content

Commit

Permalink
Tagging bugfix and updated tests to ^0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Feb 25, 2016
1 parent 0a3d663 commit ff2ec2f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
26 changes: 23 additions & 3 deletions MongoDBCachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

/**
* @author Tobias Nyholm <[email protected]>
* @author Magnus Nordlander
*/
class MongoDBCachePool extends AbstractCachePool
{
Expand All @@ -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);
Expand All @@ -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 = [
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"require": {
"php": "^5.5|^7.0",
"psr/cache": "^1.0",
"cache/adapter-common": "^0.2",
"cache/taggable-cache": "^0.3",
"cache/adapter-common": "^0.3",
"cache/taggable-cache": "^0.4",
"mongodb/mongodb": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.1",
"cache/integration-tests": "0.9.0"
"cache/integration-tests": "^0.9"
},
"provide": {
"psr/cache-implementation": "^1.0"
Expand Down

0 comments on commit ff2ec2f

Please sign in to comment.