-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Allow custom services for validator mapping cache. #12975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you @jakzal. |
…ing cache. (jakzal) This PR was merged into the 2.5 branch. Discussion ---------- [FrameworkBundle] Allow custom services for validator mapping cache. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12803 | License | MIT | Doc PR | - #9892 introduced `DoctrineCache`, but it's not really used by the FrameworkBundle. This was overlooked, therefore I think it should go into 2.5. This PR will let us to configure a service id, instead of a driver name. The only exception is apc, which is converted to `validator.mapping.cache.apc` to keep BC. Examples: ```yaml framework: validation: cache: apc # converted to validator.mapping.cache.apc ``` ```yaml framework: validation: cache: my_custom_cache_service ``` It would be nice to be able to provide a doctrine service id, instead of `CacheInterface` implementation. It could be automatically decorated with `DoctrineCache`: ```yaml framework: validation: cache: doctrine: my_doctrine_cache_service # could be provided by DoctrineCacheBundle ``` I'll work on it next. Commits ------- 4cdcf10 [FrameworkBundle] Allow custom services for validator mapping cache.
Note that a cache service implementing our interface still needs to be created by the end user. At least it's possible now. I'll work on making it easier next. |
Just two quick questions about this change:
|
I agree with @xabbuh - this looks like a very small BC break. But if you're relying on this behavior, things would blow up when your container is being built, so it'll be an obvious (and small) BC break. So perhaps it's "ok"? |
@jakzal Did you ever get to implement the doctrine decorator? |
@cmodijk no, but all you have to do in your own project is to register a new caching service: <service id="my_validator_mapping_cache" class="Symfony\Component\Validator\Mapping\Cache\DoctrineCache" public="false">
<argument type="service">
<service class="Doctrine\Common\Cache\ApcCache">
<call method="setNamespace">
<argument>%validator.mapping.cache.prefix%</argument>
</call>
</service>
</argument>
</service> and tell validator to use it: framework:
validation:
cache: my_validator_mapping_cache |
Hmm yeah but it would be nice to directly give a doctrine cache service and that the wrapping is done by Symfony because of the fact that you have the https://github.com/doctrine/DoctrineCacheBundle that generates these service id's for you. Know you need to create your own service just to wrap around the cache. With the possibility to directly inject the doctrine cache service id you don't need anything extra. |
Hi, is there a way to do this using Redis? |
@pwm yes, see the supported drivers here: https://github.com/doctrine/cache/tree/master/lib/Doctrine/Common/Cache |
…ion for validator mapping (jakzal) This PR was merged into the 2.8 branch. Discussion ---------- [FrameworkBundle] Add a doctrine cache service definition for validator mapping | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#5409 Following #12975, this PR only registers a new service so it's possible to use the new doctrine based cache implementation instead of the deprecated one. To use it, the end user would need to configure it in his `config.yml`: ```yaml framework: validation: cache: validator.mapping.cache.doctrine.apc ``` In 3.0 we'll be able to replace the deprecated definition by aliasing `validator.mapping.cache.apc` to `validator.mapping.cache.doctrine.apc`. I thought of automatic wrapping of services which implement doctrine interface, but decided it would be too magic. I'm not convinced if APC is a good default anymore and hope for some discussion. I've used it as it's also used in serializer, and probably translation (see #13986). Since there's a built in opcache in more recent PHP versions, and apcu doesn't seem to be stable, there are better choices. Perhaps a better default would be a filesystem cache (not better performing, but it works anywhere). Commits ------- 0642911 [FrameworkBundle] Add a doctrine cache service definition for validator mapping
DoctrineCache
, but it's not really used by the FrameworkBundle. This was overlooked, therefore I think it should go into 2.5.This PR will let us to configure a service id, instead of a driver name. The only exception is apc, which is converted to
validator.mapping.cache.apc
to keep BC.Examples:
It would be nice to be able to provide a doctrine service id, instead of
CacheInterface
implementation. It could be automatically decorated withDoctrineCache
:I'll work on it next.