-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
nicolas-grekas
commented
Apr 28, 2016
•
edited
Loading
edited
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 | - |
I'd happily accept some help to fix the XSD please, that should be the only remaining thing left. |
09320b9
to
bb8e5d7
Compare
->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 be To create
Hold on, I'm going to change a few things after some discussions with @javiereguiluz |
bb8e5d7
to
b2df9d6
Compare
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.redis
default_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 use https://github.com/snc/SncRedisBundle to configure the connection: framework:
cache:
system: cache.adapter.redis
default_redis_provider: snc_redis_connection_service a verbose variant of this could be: framework:
cache:
system: app.redis_cache
pools:
app.redis_cache:
adapter: cache.adapter.redis
provider: snc_redis_connection_service Or to use a Doctrine Cache provider for all app related caches: framework:
cache:
app: cache.adapter.doctrine
default_doctrine_provider: doctrine_cache_provider_service or verbose variant: framework:
cache:
app: app.doctrine_cache
pools:
app.doctrine_cache:
adapter: cache.adapter.doctrine
provider: doctrine_cache_provider_service The same would go for configuring a pool on top of a PSR-6 cache adapter. |
22bd298
to
b80a8cc
Compare
Last tweaks pushed, green, ready for review+merge:
|
eeb561e
to
f84e588
Compare
2318540
to
a34a005
Compare
private $redis; | ||
|
||
public function __construct(\Redis $redisConnection, $namespace = '', $defaultLifetime = 0) | ||
{ | ||
if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) { | ||
throw new InvalidArgumentException(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
@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. |
@@ -107,7 +107,7 @@ FrameworkBundle | |||
framework: | |||
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 the cache.
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 an app.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 be cache.serializer
. But imo we should then add the cache.
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 is framework.cache.pools.cache.serializer
which imo is not really clear why I should use the cache
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 the cache.
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 with cache.
, 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.
a34a005
to
40265e5
Compare
To be rebased on top of #18681 (which is included for now) |
51bfb86
to
493c337
Compare
…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 #18667 Commits ------- 3073efb [Cache] Add DSN based Redis connection factory
#18681 merged now |
493c337
to
c24745b
Compare
rebased |
c24745b
to
8c5e9ae
Compare
<argument /> <!-- PSR-6 provider service --> | ||
<argument /> <!-- namespace --> | ||
<argument /> <!-- default lifetime --> | ||
</service> | ||
|
||
<service id="cache.adapter.redis" class="Symfony\Component\Cache\Adapter\RedisAdapter" abstract="true"> | ||
<service id="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 made cache.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
to
8c5e9ae
Compare
Apart from how cache pool names are now treated I am 👍 for the changes. |
👍 |
8c5e9ae
to
893afda
Compare
893afda
to
a2a567d
Compare
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 caches 80a5508 [FrameworkBundle] Add cache adapters in semantic configuration