-
Notifications
You must be signed in to change notification settings - Fork 351
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
Add CacheLifeTime Handling to ContentController and ContentRouteProvider #8091
Conversation
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.
@Prokyonn lets discuss this mechanic next Week.
$cacheLifetime = $this->getCacheLifetime($templateMetadata); | ||
if ($cacheLifetime) { | ||
$this->cacheLifetimeRequestStore->setCacheLifetime($cacheLifetime); | ||
} |
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.
Step 1: filling up the cacheLifetimeRequestStore
already in the RouteDefaultsProvider
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.
Simplified this: $attributes[CacheLifetimeRequestStore::ATTRIBUTE_KEY] = $cacheLifetime;
protected function enhanceCacheLifeTime(Response $response): void | ||
{ | ||
$this->container->get('sulu_http_cache.cache_lifetime.enhancer')->enhance($response); | ||
} |
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.
Step 2 A: Enhance the Response in the Controller
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.
renamed this method to avoid conflicts with Symfony AbstractController we have a ruleset that controller protected methods need include Sulu
in its method name.
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) { |
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.
Step 2B: Simplify the Enhancer as not longer require a Structure instead get the prefilled value from cacheLifetimeRequestStore
.
352a565
to
1f94178
Compare
1f94178
to
f33162a
Compare
/** | ||
* @var CacheLifetimeRequestStore | ||
*/ | ||
private $cacheLifetimeRequestStore; |
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.
maybe we not even need this as the cacheLifetimeRequestStore
already keeps the _cacheLifeTime
request attribute in mind. Need to check this next week.
f33162a
to
0ddaf0a
Compare
c06faf1
to
784bc4a
Compare
784bc4a
to
cc5bebd
Compare
What's in this PR?
Add CacheLifeTime Handling to ContentController and RouteProvider.
Why?
We are not setting the CacheLifeTime currently in the Controller.
ToDo