/** * @test */ function it_does_not_save_empty_result_to_cache() { $this->pool->expects($this->never())->method('save'); $annotation = new CacheUpdate(['pools' => 'pool', 'tags' => 'tag', 'ttl' => 300]); $interception = new ProxyInterceptionSuffix(new \stdClass(), 'method', ['key1' => 'value1'], null); $result = $this->interceptor->interceptSuffix($annotation, $interception); $this->assertInstanceOf(EmptyResult::class, $result); }
/** * @test */ function it_removes_a_cache_tags_on_inctercept_suffix() { $this->pool->method('hasItem')->with('key')->willReturn(true); $this->pool->expects($this->once())->method('clearTags')->with(['tag1', 'tag2']); $annotation = new CacheEvict(['pools' => 'pool', 'tags' => 'tag1, tag2']); $interception = new ProxyInterceptionSuffix(new \stdClass(), 'method', ['key1' => 'value1'], 'returnValue'); $result = $this->interceptor->interceptSuffix($annotation, $interception); $this->assertInstanceOf(EvictResult::class, $result); }
public function getCachedPaginatorResult(Query $query, CacheOptions $options) : array { $hash = $this->getHash($query); $item = $this->cachePool->getItem($hash); if ($item->isHit()) { $result = $item->get(); } else { $result = $query->getArrayResult(); $item->set($result)->setTags($options->getTags()); $item->expiresAfter($options->getTtl()); $this->cachePool->save($item); } return $result; }
public function onFlush(OnFlushEventArgs $args) { $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); $scheduledEntityChanges = ['insert' => $uow->getScheduledEntityInsertions(), 'update' => $uow->getScheduledEntityUpdates(), 'delete' => $uow->getScheduledEntityDeletions()]; $cacheIds = []; foreach ($scheduledEntityChanges as $change => $entities) { foreach ($entities as $entity) { $cacheIds[get_class($entity)] = get_class($entity); } } if (count($cacheIds)) { $this->cachePool->clearTags($cacheIds); } }
public function onFlush(OnFlushEventArgs $args) { $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); $scheduledEntityChanges = ['insert' => $uow->getScheduledEntityInsertions(), 'update' => $uow->getScheduledEntityUpdates(), 'delete' => $uow->getScheduledEntityDeletions()]; $cacheIds = []; foreach ($scheduledEntityChanges as $change => $entities) { foreach ($entities as $entity) { $cacheIds[get_class($entity)] = get_class($entity); } } if (count($cacheIds)) { $this->cachePool->clearTags($cacheIds); $em->getConfiguration()->getResultCacheImpl()->delete(DataSetPaginatorInterface::RESULT_CACHE_ID); } }