Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] [WIP] Add cache warmer for normalizer cache #39853

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

Closed
wants to merge 6 commits into from

Conversation

YaFou
Copy link
Contributor

@YaFou YaFou commented Jan 15, 2021

Q A
Branch? 5.x
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #35268
License MIT
Doc PR TODO

As @bastnic said in #35268:

On every request and for every data type, we possibly traverse a lot of normalizers to check which one should be used (using support(de)Normalization methods.
It has be optimized a lot with the addition of CacheableSupportsMethodInterface but we could warm it for all entities and DTO that we can found.

⚠️ It's a first try to implement this feature and I don't know if the structure is really good. Feel free to give me feedbacks!


So, how it works?

The Serializer now uses a NormalizerChooserInterface which give two methods: chooseNormalizer and chooseDenormalizer. The code written in the Serializer is a little bit the same.
On top of that, the CacheNormalizerChooser decorates the default NormalizerChooser and give the ability to cache the results via the cache interface.

Moreover, I have introduced a new cache warmer called SerializerNormalizerChooserCacheWarmer. It will fetch all the providers defined with the interface CacheNormalizationProviderInterface and warm the cache with the CacheNormalizerChooser.

Cache normalization provider example

class PostCacheNormalizationProvider implements CacheNormalizationProviderInterface
{
    public function provide(): \Generator
    {
        yield ['json', new Post()];
        yield ['yaml', new Post()];
        yield ['json', new Author()];
    }
}

@YaFou YaFou requested a review from dunglas as a code owner January 15, 2021 21:49
@carsonbot carsonbot changed the title [WIP] [Serializer] Add cache warmer for normalizer cache [Serializer] [WIP] Add cache warmer for normalizer cache Jan 15, 2021
@YaFou YaFou force-pushed the normalization-cache-warmer branch from eb7f4da to 46f7e1a Compare January 15, 2021 21:53
@carsonbot
Copy link

Hey!

Cool, it looks like you have quite a talent.

I think @a-menshchikov has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@jderusse jderusse added this to the 5.x milestone Jan 18, 2021
@fabpot fabpot modified the milestones: 5.4, 6.1 Nov 16, 2021
@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@mtarld
Copy link
Contributor

mtarld commented Jan 7, 2024

I think that this issue has been in the meantime addressed by #49291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Serializer] Add a warmer for Serializer::$(de)normalizerCache
6 participants