Telling Symfony to Use Cached Validation From Doctrine Cache Bundle Provider

Right now Symfony on 2.7-2.8 and probably until before 3.0 will still support apc type validation caching. This will be dropped soon, at least the class support. You could still use apc past that point however you would have to wrap your ApcCache class into a DoctrineCache. The DoctrineCache is a means to adapt any Cache service implementing Doctrine\Common\Cache\Cache interface into a Symfony caching service for validation.

How this looks in code follows:

-        cache: apc
+        cache: vendor.validation_cache.doctrine 
+        vendor_filesystem_validation_cache:
+            file_system:
+                extension: cache
+                directory: %kernel.root_dir%/cache/doctrine
+    vendor.validation_cache.doctrine:
+        class: Symfony\Component\Validator\Mapping\Cache\DoctrineCache
+        arguments:
+            - @doctrine_cache.providers.vendor_filesystem_validation_cache

ArrayCache and FilesystemCache are implementations of doctrine caches, but in order to tube them in to make them available to symfony we have to use this DoctrineCache wrapper.

One extra trick to test services is to include config_prod.yml in config_dev.yml imports and comment the first lines of config_prod.yml importing config.yml since it is already imported in config_dev.yml. Then you can exercise your container:debug –show-private command without problems to test and ensure things are working correctly.


Leave a Reply

Your email address will not be published. Required fields are marked *