Doctrine\Common\Annotations\CachedReader::getMethodAnnotations PHP Method

getMethodAnnotations() public method

{@inheritDoc}
public getMethodAnnotations ( ReflectionMethod $method )
$method ReflectionMethod
    public function getMethodAnnotations(\ReflectionMethod $method)
    {
        $class = $method->getDeclaringClass();
        $cacheKey = $class->getName() . '#' . $method->getName();
        if (isset($this->loadedAnnotations[$cacheKey])) {
            return $this->loadedAnnotations[$cacheKey];
        }
        if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
            $annots = $this->delegate->getMethodAnnotations($method);
            $this->saveToCache($cacheKey, $annots);
        }
        return $this->loadedAnnotations[$cacheKey] = $annots;
    }

Usage Example

Example #1
0
 /**
  * @group performance
  */
 public function testCachedReadPerformanceWithInMemory()
 {
     $reader = new CachedReader(new AnnotationReader(), new ArrayCache());
     $method = $this->getMethod();
     $time = microtime(true);
     for ($i = 0, $c = 500; $i < $c; $i++) {
         $reader->getMethodAnnotations($method);
     }
     $time = microtime(true) - $time;
     $this->printResults('cached reader (in-memory)', $time, $c);
 }