Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Commit

Permalink
Merge 3b50a46 into 6c7de5c
Browse files Browse the repository at this point in the history
  • Loading branch information
jorissteyn committed Apr 23, 2018
2 parents 6c7de5c + 3b50a46 commit 58f502e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/MetadataRepository/CachedDoctrineMetadataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function appendFilter(FilterInterface $filter)
{
$this->repository->appendFilter($filter);

$this->clearResultsCache();

return $this;
}

Expand All @@ -93,9 +95,25 @@ public function appendVisitor(VisitorInterface $visitor)
{
$this->repository->appendVisitor($visitor);

$this->clearResultsCache();

return $this;
}

/**
* Reset the results cache.
*
* The cache is only valid for a specific combination of filters and
* visitors. If a filter or visitor is appended, the previously cached
* results are discarded by calling this method. In practice,
* visitor/filter setup is only done in the beginning of the request so
* resetting the cache has little impact on the total number of queries.
*/
private function clearResultsCache()
{
$this->cache = array();
}

/**
* @param string $entityId
* @return AbstractRole
Expand Down
24 changes: 24 additions & 0 deletions tests/MetadataRepository/CachedDoctrineMetadataRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Doctrine\DBAL\Query\QueryBuilder;
use Mockery;
use OpenConext\Component\EngineBlockMetadata\Entity\ServiceProvider;
use OpenConext\Component\EngineBlockMetadata\MetadataRepository\Filter\FilterInterface;
use OpenConext\Component\EngineBlockMetadata\MetadataRepository\Visitor\DisableDisallowedEntitiesInWayfVisitor;
use OpenConext\Component\EngineBlockMetadata\MetadataRepository\Visitor\VisitorInterface;
use PHPUnit_Framework_TestCase;

/**
Expand Down Expand Up @@ -80,4 +82,26 @@ public function testFetchServiceProviderThrowExceptions()
$repository = new CachedDoctrineMetadataRepository($doctrineRepository);
$repository->fetchServiceProviderByEntityId('test');
}

public function testAppendVisitor()
{
$doctrineRepository = Mockery::mock('OpenConext\Component\EngineBlockMetadata\MetadataRepository\DoctrineMetadataRepository');
$doctrineRepository->shouldReceive('appendVisitor');

$repository = new CachedDoctrineMetadataRepository($doctrineRepository);
$repository->appendVisitor(
Mockery::mock(VisitorInterface::class)
);
}

public function testAppendFilter()
{
$doctrineRepository = Mockery::mock('OpenConext\Component\EngineBlockMetadata\MetadataRepository\DoctrineMetadataRepository');
$doctrineRepository->shouldReceive('appendFilter');

$repository = new CachedDoctrineMetadataRepository($doctrineRepository);
$repository->appendFilter(
Mockery::mock(FilterInterface::class)
);
}
}

0 comments on commit 58f502e

Please sign in to comment.