doctrine/oxm — Issue #25: Not all metadata is cached
Author: jakzal
Created: 2012-02-02 17:10:23+00:00
State: open

`XmlMarshaller::doUnmarshal()` calls `ClassMetadataFactory::getAllXmlNodes()` which makes performance sensitive operations every time. The result is not cached although cache driver is available in the ClassMetadataFactory.

Second thing is I'm using Apc cache driver and only first request successfully unmarshalls XML. Every other fails as `ClassMetadataFactory::getAllXmlNodes()` returns an empty array.

Flow is as follows:

* [XmlMarshaller::doUnmarshal()](https://github.com/doctrine/oxm/blob/975dcb3dffbec44886631fb9bb34335079e35077/lib/Doctrine/OXM/Marshaller/XmlMarshaller.php#L215)

```
$allMappedXmlNodes = $this->classMetadataFactory->getAllXmlNodes();
```

* [ClassMetadataFactory::getAllXmlNodes()](https://github.com/doctrine/oxm/blob/975dcb3dffbec44886631fb9bb34335079e35077/lib/Doctrine/OXM/Mapping/ClassMetadataFactory.php#L154)

```
$this->getAllMetadata();
```

* [ClassMetadataFactory::getAllMetadata()](https://github.com/doctrine/oxm/blob/975dcb3dffbec44886631fb9bb34335079e35077/lib/Doctrine/OXM/Mapping/ClassMetadataFactory.php#L135)

```
foreach ($this->driver->getAllClassNames() as $className) {
$mappings[] = $this->getMetadataFor($className);
}
```

* [AnnotationDriver::getAllClassNames()](https://github.com/doctrine/oxm/blob/975dcb3dffbec44886631fb9bb34335079e35077/lib/Doctrine/OXM/Mapping/Driver/AnnotationDriver.php#L295) searches entity paths for class names. Result of these inefficient operations is not cached.

Many of ClassMetadataFactory method call initialize() method to lazy load stuff. Comment to [ClassMetadataFactory ::initialize()](https://github.com/doctrine/oxm/blob/975dcb3dffbec44886631fb9bb34335079e35077/lib/Doctrine/OXM/Mapping/ClassMetadataFactory.php#L159) says:

> Lazy initialization of this stuff, especially the metadata driver,
> since these are not needed at all when a metadata cache is active.

Comment says one thing but code does another. Both drivers are always initialized.

IMHO cache driver should be initialized and used in the first place. Metadata driver shouldn't be needed as long as we can get information from cache.

I might have a bad understanding of how these things should work. I'm experiencing performance problems and would like to work on improvements.