Repository navigation
Purge through the purger API Platform's BufferedPurger decorates (#610) - #618
Merged
Merged
Conversation
API Platform dev-main (api-platform/core#8869) buffers purges during a main request and flushes them on kernel.response, where a failure is a 500 the bundle cannot catch. Give HttpCachePurger and HttpCacheFlusher the buffer's inner purger so #311 holds: a failed purge after a write is logged, and an explicit purge is a 502.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #618 +/- ##
=========================================
Coverage 97.25% 97.25%
- Complexity 5606 5611 +5
=========================================
Files 461 461
Lines 14366 14378 +12
=========================================
+ Hits 13971 13984 +13
+ Misses 395 394 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #610.
Problem
api-platform/core dev-main (api-platform/core#8869, "purge once per request", in no release yet) adds
ApiPlatform\HttpCache\BufferedPurgerasapi_platform.http_cache.purger.buffered. It decoratesapi_platform.http_cache.purger. During a main request it holds everypurge()call, andHttpCachePurgeBufferListenerflushes it onkernel.response(priority -1024). Upstream's goal is to stop a write being purged twice: once by AP's Doctrine listener and once byPurgeTagsProcessor. Outside a request (console, messenger) purges are still immediate. The PR adds no config switch and no event. The only hooks are the service ids.The bundle injected
api_platform.http_cache.purger, so on dev-main it got the buffered purger.HttpCachePurger::send()then only buffered the tags, and the real purge ran in AP's listener. A failure there is aPurgeFailedExceptionthe bundle cannot catch, so it became a 500. That broke #311 in two ways:Approach
The bundle's purger is now the buffer's inner purger.
ApiPlatformCompilerPasschecks whetherapi_platform.http_cache.purger.bufferedis defined and decorates a service. If it does,HttpCachePurger(argument 2) andHttpCacheFlusher(argument 0) get the buffer's inner purger: its renamed inner id, else<id>.inner. Each purge then runs, and fails, inside the bundle's own call, as before.HttpCacheFlusher::canFlush()checksinstanceof SouinPurger, which is false on the buffered decorator. Without this change, a Souin site'sPOST /_/http_cache/purgewith no body would have become a 501.I rejected the other options:
kernel.response, so they could not return 502.flush()from the bundle: it would need aBufferedPurgertype check insrc/, and it would stop AP's buffering for the rest of the request.Tests
ApiPlatformCompilerPassTest(bareContainerBuilder) covers:HttpCachePurgeFailureTest(both tests);PurgeHttpCacheOperationTest::test_a_scoped_purge_that_fails_is_a_502.paratest -p4on both suites: stable (AP v5.0.9) 6450 OK; NEXT setup (AP dev-main, Symfony 8.2, temporary copy, not committed) 6450 OK. Before the fix, the NEXT setup failed those 3 tests.API_PLATFORM_USE_SYMFONY_LISTENERS=1: 1832 OK.🤖 Generated with Claude Code