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:

 framework:
     validation:
-        cache: apc
+        cache: vendor.validation_cache.doctrine 
 
 doctrine_cache:
     providers:
+        vendor_filesystem_validation_cache:
+            file_system:
+                extension: cache
+                directory: %kernel.root_dir%/cache/doctrine
 
 services:
+    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.

Enjoy!

Doctrine File System Caching with Doctrine Cache Bundle

Some people had experience some difficulty configuring a filesystem cache type. Symfony by default comes with some caching because of the doctrine bundle, however if one wants to extend to more types one has to install the Doctrine Cache Bundle which brings more provides into place. Now if you want to still instruct doctrine to cache metadata, the results and the query caching with these service providers then this is the way:

doctrine:
    orm:
        metadata_cache_driver:
            type: service
            id: doctrine_cache.providers.vendor_filesystem_metadata_cache
        result_cache_driver:
            type: service
            id: doctrine_cache.providers.vendor_filesystem_result_cache
        query_cache_driver:
            type: service
            id: doctrine_cache.providers.vendor_filesystem_query_cache

doctrine_cache:
    providers:
        vendor_filesystem_metadata_cache:
            file_system:
                extension: cache
                directory: %kernel.root_dir%/cache/doctrine
        vendor_filesystem_result_cache:
            file_system:
                extension: cache
                directory: %kernel.root_dir%/cache/doctrine
        vendor_filesystem_query_cache:
            file_system:
                extension: cache
                directory: %kernel.root_dir%/cache/doctrine

I hope this resolves it for you when you need it.