Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Merge requests
!8154
Set proper expire headers, based on
#3447821
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Closed
Set proper expire headers, based on
#3447821
issue/drupal-3444257:3444257-resourceobjectnormalizergetnormalization-can-result
into
11.x
Overview
29
Commits
22
Pipelines
24
Changes
2
3 open threads
Show all comments
Closed
Set proper expire headers, based on #3447821
Björn Brala
requested to merge
issue/drupal-3444257:3444257-resourceobjectnormalizergetnormalization-can-result
into
11.x
May 22, 2024
Overview
29
Commits
22
Pipelines
24
Changes
2
3 open threads
Show all comments
Closes
#3444257
0
0
Merge request reports
Compare
11.x
version 21
8da18832
11 months ago
version 20
715c4758
Aug 1, 2024
version 19
9b394689
Aug 1, 2024
version 18
a1771f93
Jul 22, 2024
version 17
f5ffa895
Jul 22, 2024
version 16
99e1a37b
Jun 18, 2024
version 15
996ff8e5
Jun 18, 2024
version 14
082b956b
May 27, 2024
version 13
6954e781
May 25, 2024
version 12
ca8a651d
May 25, 2024
version 11
b8d8a982
May 25, 2024
version 10
dc20703f
May 24, 2024
version 9
b9318736
May 24, 2024
version 8
e8a83667
May 24, 2024
version 7
29b30b40
May 24, 2024
version 6
fa9761b3
May 24, 2024
version 5
1f72df7e
May 24, 2024
version 4
7e51b70a
May 24, 2024
version 3
4a8350e6
May 24, 2024
version 2
e95cf883
May 22, 2024
version 1
ed9cf00c
May 22, 2024
11.x (base)
and
latest version
latest version
872f9151
22 commits,
9 months ago
version 21
8da18832
21 commits,
11 months ago
version 20
715c4758
20 commits,
Aug 1, 2024
version 19
9b394689
19 commits,
Aug 1, 2024
version 18
a1771f93
18 commits,
Jul 22, 2024
version 17
f5ffa895
17 commits,
Jul 22, 2024
version 16
99e1a37b
16 commits,
Jun 18, 2024
version 15
996ff8e5
15 commits,
Jun 18, 2024
version 14
082b956b
15 commits,
May 27, 2024
version 13
6954e781
13 commits,
May 25, 2024
version 12
ca8a651d
12 commits,
May 25, 2024
version 11
b8d8a982
11 commits,
May 25, 2024
version 10
dc20703f
10 commits,
May 24, 2024
version 9
b9318736
9 commits,
May 24, 2024
version 8
e8a83667
9 commits,
May 24, 2024
version 7
29b30b40
8 commits,
May 24, 2024
version 6
fa9761b3
7 commits,
May 24, 2024
version 5
1f72df7e
6 commits,
May 24, 2024
version 4
7e51b70a
5 commits,
May 24, 2024
version 3
4a8350e6
4 commits,
May 24, 2024
version 2
e95cf883
2 commits,
May 22, 2024
version 1
ed9cf00c
1 commit,
May 22, 2024
2 files
+
99
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php
+
34
−
1
View file @ 872f9151
Edit in single-file editor
Open in Web IDE
Show comments on this file
Show full file
@@ -5,6 +5,7 @@
use
Drupal\Core\Cache\CacheableMetadata
;
use
Drupal\Core\Cache\VariationCacheInterface
;
use
Drupal\jsonapi\JsonApiResource\ResourceObject
;
use
Drupal\jsonapi\Normalizer\Value\CacheableNormalization
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
use
Symfony\Component\HttpFoundation\RequestStack
;
use
Symfony\Component\HttpKernel\Event\TerminateEvent
;
@@ -102,7 +103,39 @@ public function get(ResourceObject $object) {
}
$cached
=
$this
->
variationCache
->
get
(
$this
->
generateCacheKeys
(
$object
),
new
CacheableMetadata
());
return
$cached
?
$cached
->
data
:
FALSE
;
if
(
!
$cached
)
{
return
FALSE
;
}
// When a cache hit occurs, we first calculate the remaining time before the
// cached record expires, ensuring that we do not reset the expiration with
// one that might have been generated on an earlier timestamp. This is done
// by subtracting the current timestamp from the cached record's expiration
// timestamp. If the max-age is set, we adjust it by merging the calculated
// remaining time with the original max-age of the cached item, ensuring
// that the expiration remains accurate based on the current cache state
// and timestamp.
$normalizer_values
=
$cached
->
data
;
assert
(
is_array
(
$normalizer_values
));
if
(
$cached
->
expire
>=
0
)
{
$max_age
=
max
(
$cached
->
expire
-
$this
->
requestStack
->
getCurrentRequest
()
->
server
->
get
(
'REQUEST_TIME'
),
0
);
$cacheability
=
new
CacheableMetadata
();
$cacheability
->
setCacheMaxAge
(
$max_age
);
$subsets
=
[
ResourceObjectNormalizationCacher
::
RESOURCE_CACHE_SUBSET_BASE
,
ResourceObjectNormalizationCacher
::
RESOURCE_CACHE_SUBSET_FIELDS
,
];
foreach
(
$subsets
as
$subset
)
{
foreach
(
$normalizer_values
[
$subset
]
as
$name
=>
$normalization
)
{
assert
(
$normalization
instanceof
CacheableNormalization
);
if
(
$normalization
->
getCacheMaxAge
()
>
0
)
{
$normalizer_values
[
$subset
][
$name
]
=
$normalization
->
withCacheableDependency
(
$cacheability
);
}
}
}
}
return
$normalizer_values
;
}
/**
Loading