In my Drupal 9 site with CKEditor 4 and I have created "media gallery" media type, which displays set of images (using slideshow module). So, when I click "insert media" CKEditor button for tool bar I have media selector popup, I can select and insert media gallery and that works well.
Only problem is that when media is inserted, that AJAX call is cached. So if I for example edit gallery, add another image or remove one and I go to insert that gallery in CKEditor I get old gallery, in state before my recent editing.
When I look at entity media it self it gets updated immediately, but AJAX call CKEditor makes is cached.
How can I disable that caching? Or force cache rebuild when gallery is saved?
Update:
I figured out that at:
web/core/modules/media/src/Controller/MediaFilterController.php
preview method is setting MaxAge value to 300 (5 minutes).
// Note that we intentionally do not use:
// - \Drupal\Core\Cache\CacheableResponse because caching it on the server
// side is wasteful, hence there is no need for cacheability metadata.
// - \Drupal\Core\Render\HtmlResponse because there is no need for
// attachments nor cacheability metadata.
return (new Response($html, 200, $headers))
// Do not allow any intermediary to cache the response, only the end user.
->setPrivate()
// Allow the end user to cache it for up to 5 minutes.
->setMaxAge(300);
If I change parameter to 0 it starts working well. Now, is there a reason why this caching is needed and what would be the optimal way to solve this issue? I saw that this code has long history, yet since it was a separate module:
https://www.drupal.org/project/entity_embed/issues/3182698