Doctrine Common
  1. Doctrine Common
  2. DCOM-12

Annotation caching causes application instance mixups

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.0.0-BETA2, 2.0.0-BETA3, 2.0.0-BETA4
    • Fix Version/s: None
    • Component/s: Annotations
    • Labels:
      None

      Description

      Take a look at lib/Doctrine/Common/Annotations/AnnotationReader.php:137

       
          /**
           * Gets the annotations applied to a class.
           * 
           * @param string|ReflectionClass $class The name or ReflectionClass of the class from which
           * the class annotations should be read.
           * @return array An array of Annotations.
           */
          public function getClassAnnotations(ReflectionClass $class)
          {
              $cacheKey = $class->getName() . self::$CACHE_SALT;
      
              // Attempt to grab data from cache
              if (($data = $this->cache->fetch($cacheKey)) !== false) {
                  return $data;
              }
              
              $annotations = $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
              $this->cache->save($cacheKey, $annotations, null);
              
              return $annotations;
          }
      

      It uses the class name and a static salt to create a cache key. Actually, everything in that class uses a class name to assemble a cache key.

      This makes it impossible to have mulitple instances of the same application in different states. Practically: it makes it impossible to have testing and staging, or staging and production versions on the same host if they use the same type of caching (which you sort of need in a staging environment).

        Activity

        Hide
        John Kleijn added a comment -

        Confused "fix" with "affects", sorry

        Show
        John Kleijn added a comment - Confused "fix" with "affects", sorry
        Hide
        Roman S. Borschel added a comment -

        Why not just use the namespacing facilities of the cache drivers?

        Show
        Roman S. Borschel added a comment - Why not just use the namespacing facilities of the cache drivers?
        Hide
        John Kleijn added a comment -

        Cause I didn't read the caching docs?

        Show
        John Kleijn added a comment - Cause I didn't read the caching docs?

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            John Kleijn
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: