Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle] Semantic config for app/system/pool caches#18667
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedApr 28, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I'd happily accept some help to fix the XSD please, that should be the only remaining thing left. |
| ->scalarNode('adapter') | ||
| ->info('The cache pool adapter service to use as template definition.') | ||
| ->defaultValue('cache.adapter.shared') | ||
| ->info('The create a new pool based on this adapter service.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should beTo create
nicolas-grekas commentedApr 29, 2016
Hold on, I'm going to change a few things after some discussions with@javiereguiluz |
nicolas-grekas commentedApr 29, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Following suggestions from@javiereguiluz and@fabpot, configuration is now the following: Pre-configured cache pool services are now: Configuration is made easy for those two, using full service names to define which adapter should be used for each of them. E.g. to use APCu for all system caches: framework:cache:system:cache.adapter.apcu To use Redis for all app related caches: framework:cache:app:cache.adapter.redisdefault_redis_provider:redis://1.2.3.4:5678 As you can see, this PR also adds a factory for creating Redis connection based on a DSN. Then of course you can go to more advanced configurations to redefine either custom adapters or regular pools (pre-defined or not). Adapter and pool configurations are merged in a single E.g. to define a new system cache pool accessible with framework:cache:pools:my_local_cache_pool:adapter:cache.system# overwrite the default which is "cache.app"public:true# new cache pools are private by default E.g. to use Redis for all system pools and usehttps://github.com/snc/SncRedisBundle to configure the connection: framework:cache:system:cache.adapter.redisdefault_redis_provider:snc_redis_connection_service a verbose variant of this could be: framework:cache:system:app.redis_cachepools:app.redis_cache:adapter:cache.adapter.redisprovider:snc_redis_connection_service Or to use a Doctrine Cache provider for all app related caches: framework:cache:app:cache.adapter.doctrinedefault_doctrine_provider:doctrine_cache_provider_service or verbose variant: framework:cache:app:app.doctrine_cachepools:app.doctrine_cache:adapter:cache.adapter.doctrineprovider:doctrine_cache_provider_service The same would go for configuring a pool on top of a PSR-6 cache adapter. |
22bd298 tob80a8ccComparenicolas-grekas commentedApr 29, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Last tweaks pushed, green, ready for review+merge:
|
eeb561e tof84e588Compare2318540 toa34a005Compare| if (preg_match('#[^-+_.A-Za-z0-9]#',$namespace,$match)) { | ||
| thrownewInvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.',$match[0])); | ||
| } | ||
| if (!$redisConnection->isConnected()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Are you sure that it is a good idea to require an established connection in the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
good catch, check removed
xabbuh commentedApr 30, 2016
@nicolas-grekas I'd be happy to split the PR in two (one for the Redis related changes and one for the semantic config). That would make reviewing a bit easier. |
| cache: | ||
| pools: | ||
| serializer: | ||
| cache.serializer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Why do we repeat thecache. prefix here. Imo this looks weird as it repeats what we already know from the config tree (I mean we are configuring the cache, why do we want to reflect that in the name here too?)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
because I've been told that Symfony core prefers explicit over implicit & "magic" conventions. This in fact is much more flexible and doesn't force any service prefix. See examples above where anapp.doctrine_cache pool is created. We don't have to teach any special convention here. Just give a service name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I understand that we want the service to becache.serializer. But imo we should then add thecache. prefix here:https://github.com/nicolas-grekas/symfony/blob/cache-config/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1059
Otherwise, the full config path we use here isframework.cache.pools.cache.serializer which imo is not really clear why I should use thecache part twice here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
And by the way, adding thecache. prefix in the extension when registering the definition will also prevent us from potentially having conflicting service names because when people configure their own cache pools, they will not always think of adding the prefix here explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think I prefer to be explicit. Whenever possible we try to use the full service name in configuration and that's what is done here. If the end user does not want to prefix their service name withcache., it's not a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
But we then still have the point that the configured names are directly used as service ids which can easily lead to conflicts (we don't do that anywhere else, do we?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
After re-reading#18667 (comment) think we can stop the discussion here as it was based on a misunderstand on my end.
👍 for how the PR is right now.
nicolas-grekas commentedApr 30, 2016
To be rebased on top of#18681 (which is included for now) |
51bfb86 to493c337Compare…s-grekas)This PR was merged into the 3.1-dev branch.Discussion----------[Cache] Add DSN based Redis connection factory| Q | A| ------------- | ---| Branch? | 3.1| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -Required by#18667Commits-------3073efb [Cache] Add DSN based Redis connection factory
fabpot commentedMay 1, 2016
#18681 merged now |
nicolas-grekas commentedMay 1, 2016
rebased |
| </service> | ||
| <serviceid="cache.adapter.redis"class="Symfony\Component\Cache\Adapter\RedisAdapter"abstract="true"> | ||
| <serviceid="cache.adapter.redis"class="Symfony\Component\Cache\Adapter\RedisAdapter"abstract="true"lazy="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I just madecache.adapter.redis lazy so that no connection is opened unless needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
but I'm not sure this is required, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
we don't have any lazy service in Symfony core as it depends on a deps that is not a hard dep. Lazy means that the service is wrapped with a proxy, which adds its own layer of complexity, so I would avoid that if possible.
e4abdc8 to8c5e9aeComparexabbuh commentedMay 2, 2016
Apart from how cache pool names are now treated I am 👍 for the changes. |
dunglas commentedMay 2, 2016
👍 |
fabpot commentedMay 4, 2016
Thank you@nicolas-grekas. |
…caches (tgalopin, nicolas-grekas)This PR was merged into the 3.1-dev branch.Discussion----------[FrameworkBundle] Semantic config for app/system/pool caches| Q | A| ------------- | ---| Branch? | 3.1| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#18625| License | MIT| Doc PR | -Commits-------a2a567d [FrameworkBundle] Simplify config for app/system/pool caches80a5508 [FrameworkBundle] Add cache adapters in semantic configuration
Uh oh!
There was an error while loading.Please reload this page.