Skip to content

Commit

Permalink
Create hash of the name for cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemix committed Jul 6, 2015
1 parent 2c687f3 commit d5f7275
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/ServiceManager/DiAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator
}

$this->initializeCache($serviceLocator);
$this->setChangeSet($this->cache->getItem($name));
$this->setChangeSet($this->cache->getItem(md5($name)));

if ($this->getChangeSet() instanceof ChangeSet) {
// Positive result available via cache
Expand All @@ -61,13 +61,13 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator

if ($this->getChangeSet()->isAnnotated()) {
// Service is annotated to cache results
$this->cache->setItem($name, $this->getChangeSet());
$this->cache->setItem(md5($name), $this->getChangeSet());
return true;
}

// Service is not annotated
// Cache false for it
$this->cache->setItem($name, false);
$this->cache->setItem(md5($name), false);
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions test/ServiceManager/DiAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testCanCreateServiceWithNameReturnsResultFromCache()

$this->cacheAdapter->expects($this->once())
->method('getItem')
->with($this->equalTo('injectable'))
->with($this->equalTo(md5('injectable')))
->will($this->returnValue($result));

$this->cacheAdapter->expects($this->never())
Expand All @@ -88,7 +88,7 @@ public function testCanCreateServiceWithNameSetsFalseInCacheIfServiceNotAnnotate
{
$this->cacheAdapter->expects($this->once())
->method('getItem')
->with($this->equalTo('injectable'))
->with($this->equalTo(md5('injectable')))
->will($this->returnValue(false));

$result = $this->getMockBuilder(ChangeSet::class)
Expand All @@ -107,7 +107,7 @@ public function testCanCreateServiceWithNameSetsFalseInCacheIfServiceNotAnnotate

$this->cacheAdapter->expects($this->once())
->method('setItem')
->with($this->equalTo('injectable'), $this->equalTo(false));
->with($this->equalTo(md5('injectable')), $this->equalTo(false));

$this->serviceLocator->expects($this->at(0))
->method('get')
Expand Down Expand Up @@ -144,12 +144,12 @@ public function testCanCreateServiceWithNameSetsResultInCacheIfAnnotated()

$this->cacheAdapter->expects($this->once())
->method('getItem')
->with($this->equalTo('injectable'))
->with($this->equalTo(md5('injectable')))
->will($this->returnValue(false));

$this->cacheAdapter->expects($this->once())
->method('setItem')
->with($this->equalTo('injectable'), $this->equalTo($result));
->with($this->equalTo(md5('injectable')), $this->equalTo($result));

$this->serviceLocator->expects($this->at(0))
->method('get')
Expand Down

0 comments on commit d5f7275

Please sign in to comment.