Skip to content

Add CacheLifeTime Handling to ContentController and ContentRouteProvider #8091

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

Merged

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Aug 14, 2025

Q A
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? no
Fixed tickets fixes #
Related issues/PRs requires #8073
License MIT
Documentation PR sulu/sulu-docs#

What's in this PR?

Add CacheLifeTime Handling to ContentController and RouteProvider.

Why?

We are not setting the CacheLifeTime currently in the Controller.

ToDo

  • Upgrade with changed services

Copy link
Member Author

@alexander-schranz alexander-schranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Prokyonn lets discuss this mechanic next Week.

Comment on lines 117 to 120
$cacheLifetime = $this->getCacheLifetime($templateMetadata);
if ($cacheLifetime) {
$this->cacheLifetimeRequestStore->setCacheLifetime($cacheLifetime);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 1: filling up the cacheLifetimeRequestStore already in the RouteDefaultsProvider

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified this: $attributes[CacheLifetimeRequestStore::ATTRIBUTE_KEY] = $cacheLifetime;

Comment on lines 87 to 90
protected function enhanceCacheLifeTime(Response $response): void
{
$this->container->get('sulu_http_cache.cache_lifetime.enhancer')->enhance($response);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 2 A: Enhance the Response in the Controller

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed this method to avoid conflicts with Symfony AbstractController we have a ruleset that controller protected methods need include Sulu in its method name.

Comment on lines +26 to +30
public function enhance(Response $response): void
{
if (!\method_exists($structure, 'getCacheLifeTime')) {
return;
}

$cacheLifetimeData = $structure->getCacheLifeTime();
$cacheLifetime = $this->cacheLifetimeResolver->resolve(
$cacheLifetimeData['type'],
$cacheLifetimeData['value']
);

$requestCacheLifetime = $this->cacheLifetimeRequestStore->getCacheLifetime();

if (null !== $requestCacheLifetime && $requestCacheLifetime < $cacheLifetime) {
$cacheLifetime = $requestCacheLifetime;
}
$cacheLifetime = $this->cacheLifetimeRequestStore->getCacheLifetime();

// when structure cache-lifetime disabled - return
if (0 === $cacheLifetime) {
if (!$cacheLifetime) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 2B: Simplify the Enhancer as not longer require a Structure instead get the prefilled value from cacheLifetimeRequestStore.

@alexander-schranz alexander-schranz added the DX Affecting the end developer label Aug 14, 2025
@alexander-schranz alexander-schranz force-pushed the feature/new-cache-behaviour branch 3 times, most recently from 352a565 to 1f94178 Compare August 14, 2025 16:59
@alexander-schranz alexander-schranz changed the title Add CacheLifeTime Handling to ContentController and RouteProvider Add CacheLifeTime Handling to ContentController and ContentRouteProvider Aug 14, 2025
@alexander-schranz alexander-schranz force-pushed the feature/new-cache-behaviour branch from 1f94178 to f33162a Compare August 14, 2025 17:02
@alexander-schranz
Copy link
Member Author

Ready for Review: f33162a @Prokyonn

/**
* @var CacheLifetimeRequestStore
*/
private $cacheLifetimeRequestStore;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we not even need this as the cacheLifetimeRequestStore already keeps the _cacheLifeTime request attribute in mind. Need to check this next week.

@alexander-schranz alexander-schranz force-pushed the feature/new-cache-behaviour branch from f33162a to 0ddaf0a Compare August 18, 2025 07:56
@alexander-schranz alexander-schranz marked this pull request as ready for review August 18, 2025 07:56
@alexander-schranz alexander-schranz force-pushed the feature/new-cache-behaviour branch 2 times, most recently from c06faf1 to 784bc4a Compare August 18, 2025 08:46
@alexander-schranz alexander-schranz force-pushed the feature/new-cache-behaviour branch from 784bc4a to cc5bebd Compare August 18, 2025 08:59
@alexander-schranz alexander-schranz merged commit 4c67ffe into sulu:3.0 Aug 18, 2025
9 checks passed
@alexander-schranz alexander-schranz deleted the feature/new-cache-behaviour branch August 18, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Affecting the end developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants