-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Deprecate using doctrine/cache in favour of PSR-6 #144
Conversation
8e33555
to
d062763
Compare
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've left some feedback below.
@greg0ire what settings do I need to pass to update the lock file? Looks like psalm does not like something about this change, but I assume it's due to composer.lock changes, not the cache change itself.
"doctrine/event-manager": "^1.0" | ||
"doctrine/event-manager": "^1.0", | ||
"psr/cache": "^1.0", | ||
"symfony/cache": "^4.4|^5.0" |
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.
This is used to provide the forward/compatibility layer. Once we drop that in 3.0, this becomes a dev dependency.
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.
symfony/cache
has a dev-dependency on doctrine/cache
, so this means a circular dependency (not for us, but for them when they are in dev mode). I think this might be OK though since it's not meant to last, and since symfony seems to be resorting to COMPOSER_ROOT_VERSION
in its CI already: https://github.com/symfony/symfony/search?q=COMPOSER_ROOT_VERSION
Still, we might want to check if we don't break their pipeline after releasing this (or merging it? I think they have builds that use untagged versions).
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.
How is there a circular dependency? This is doctrine/persistence, not doctrine/cache.
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.
How is there a circular dependency?
symfony/symfony
depends on doctrine/persistence
and replaces symfony/cache
. Anyway, we should be good 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.
Right, nevermind my comment, not sure what I meant but I must have been confused.
@@ -400,6 +445,11 @@ public function getReflectionService() | |||
return $this->reflectionService; | |||
} | |||
|
|||
protected function getCacheKey(string $realClassName): string | |||
{ | |||
return str_replace('\\', '__', $realClassName) . $this->cacheSalt; |
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.
This (along with the changed cache salt) will invalidate existing caches. We'll have to check if existing implementations manually mess with cache keys, in which case we'll have to come back and check the impact of this change.
|
||
$metadata = $this->createMock(ClassMetadata::class); | ||
assert($metadata instanceof ClassMetadata); | ||
public function testWillNotCacheFallbackMetadata(): void |
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 duplicated that test, as I realised that using the onMetadataNotFound
fallback does not cache that metadata. Since I assume this is intended, I haven't made changes and instead opted to codify that behaviour in tests.
I guess you will need to fix the conflicts for a new build to be triggered and the SA to be fixed (I merged up 2.1.x into 2.2.x, it contains a fix for your issue.) |
My experience with |
4c21399
to
9b17158
Compare
Not sure why there are this many PHPStan errors, but a lot of them look like they could be fixed by setting up |
Not sure where those are coming from. The problem may be that I need to update the lock file due to dependency changes and it installs a newer version than it did before. We should probably document this in our contribution docs. |
lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php
Outdated
Show resolved
Hide resolved
lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php
Outdated
Show resolved
Hide resolved
ee2df30
to
c2e4044
Compare
tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php
Outdated
Show resolved
Hide resolved
tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php
Outdated
Show resolved
Hide resolved
tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php
Outdated
Show resolved
Hide resolved
tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php
Outdated
Show resolved
Hide resolved
tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php
Outdated
Show resolved
Hide resolved
@greg0ire any idea why psalm suddenly complains about |
Woops sorry I'm only noticing your ping now, and I think you are right, see #156 |
Ah I need to merge up |
Co-authored-by: Grégoire Paris <[email protected]>
Co-authored-by: Alexander M. Turek <[email protected]>
ac52449
to
3ee8ca7
Compare
Thanks @alcaeus ! |
public function setCache(CacheItemPoolInterface $cache): void | ||
{ | ||
$this->cache = $cache; | ||
$this->cacheDriver = new DoctrineProvider($cache); |
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.
this should use the doctrine/cache PSR-6 provider instead, which is available in the latest version
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.
The DoctrineAdapter
could be replaced. I've created doctrine/cache#366 to also include this class in doctrine/cache so we no longer have external dependencies for the forward and backward compatibility layers. I'll follow up with a PR here once this is done.
This PR deprecates the
getCacheDriver
andsetCacheDriver
methods in the abstract metadata factory in favour ofsetCache
andgetCache
which work with PSR-6 cache instances.To make the transition easier, this PR provides a full backward and forward compatibility layer. When using
setCache
to use a PSR-6 cache,getCacheDriver
will expose a doctrine/cache instance that wraps the PSR-6 cache. Similarly, when usingsetCacheDriver
with a doctrine/cache instance,getCache
will expose a PSR-6 cache that wraps the original cache.The new protected
getCacheKey
method is used to avoid hardcoding cache keys in tests and can also be used by extending implementations to work with cache items directly (although they shouldn't).