Below you will find pages that utilize the taxonomy term “Metadata”
Symfony2 & Metadata: Caching Class- and PropertyMetadata
After creating a metadata factory and metadata drivers, we now need a way to cache the metadata, since collecting them at each request is way too inefficient. Luckily, the Metadata library provides us with a FileCache
(though it may be any kind of a cache, as long as it implements the same CacheInterface
). First, we make the FileCache
available as a service, and add a call to setCache
on the metadata factory:
<parameter key="matthias_annotation.metadata.cache_class">Metadata\Cache\FileCache</parameter>
<!-- ... -->
<service id="matthias_annotation.metadata.cache" class="%matthias_annotation.metadata.cache_class%" public="false">
<argument /><!-- the cache directory (to be set later) -->
</service>
<service id="matthias_annotation.metadata_factory" class="%matthias_annotation.metadata_factory.class%" public="false">
<argument type="service" id="matthias_annotation.driver_chain" />
<!-- call setCache with the new cache service: -->
<call method="setCache">
<argument type="service" id="matthias_annotation.metadata.cache" />
</call>
</service>
This provides the metadata factory with the file cache.
Symfony2: Writing a Yaml Driver for your Metadata Factory
In my previous post, I wrote about annotations and how to gather them using a metadata factory and an annotation driver. I also mentioned a future post in which I explain other ways of collecting metadata, namely by locating and parsing files in several different formats (distinguished by their extension). This is the post. In the case of our @DefaultValue
annotation, I’m thinking of a Yaml flavoured alternative. This allows us to store all default values as an array of property “name” - “value” pairs, like