/** * Whether or not the item needs to be parsed and cached. * * @param string $schemaName * @param string $cacheItem * @return bool */ protected function shouldBuildCacheItem($schemaName, $cacheItem) { $cacheOutOfDate = false; if ($this->cache->getUseAutoCache()) { $lastModTime = $this->parser->getSchemaModificationTime($schemaName); $cacheCreationTime = $this->cache->getCacheCreationTime(LdapObjectSchema::getCacheType(), $cacheItem); $cacheOutOfDate = !$lastModTime || $lastModTime > $cacheCreationTime; } return $cacheOutOfDate || !$this->cache->contains(LdapObjectSchema::getCacheType(), $cacheItem); }
function it_should_not_call_the_load_schema_event_when_retrieving_from_the_cache(CacheInterface $cache, SchemaParserInterface $parser, $dispatcher) { $cache->getUseAutoCache()->willReturn(true); $cache->contains(LdapObjectSchema::getCacheType(), 'ad.user')->willReturn(true); $cache->getCacheCreationTime(LdapObjectSchema::getCacheType(), 'ad.user')->willReturn(new \DateTime('2015-1-3')); $cache->set(Argument::any())->shouldNotBeCalled(); $cache->get(LdapObjectSchema::getCacheType(), 'ad.user')->willReturn(new LdapObjectSchema('ad', 'user')); $parser->parse('ad', 'user')->shouldNotBeCalled(); $parser->getSchemaModificationTime('ad')->willReturn(new \DateTime('2015-1-2')); new LdapObjectSchemaEvent(Event::LDAP_SCHEMA_LOAD, new LdapObjectSchema('ad', 'user')); $dispatcher->dispatch(Argument::type('\\LdapTools\\Event\\LdapObjectSchemaEvent'))->shouldNotBeCalled(); $this->beConstructedWith($cache, $parser, $dispatcher); $this->get('ad', LdapObjectType::USER); }
public function it_should_always_return_null_when_calling_get() { $item = new LdapObjectSchema('foo', 'bar'); $this->get($item->getCacheType(), $item->getSchemaName() . '.' . $item->getObjectType())->shouldBeNull(); }
function it_should_be_case_insensitive_when_looking_up_an_item_in_the_cache() { $this->setCacheFolder($this->testCacheDir); $item = new LdapObjectSchema('foo', 'bar'); $this->set($item); $this->contains(LdapObjectSchema::getCacheType(), 'Foo.Bar')->shouldBeEqualTo(true); $this->get(LdapObjectSchema::getCacheType(), 'Foo.Bar')->shouldBeLike($item); $this->deleteAll(); }