8000 [Cache] Allow skipping serializer for a specific cache pool · Issue #39355 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Allow skipping serializer for a specific cache pool #39355

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
yellow1912 opened this issue Dec 7, 2020 · 1 comment
Closed

[Cache] Allow skipping serializer for a specific cache pool #39355

yellow1912 opened this issue Dec 7, 2020 · 1 comment

Comments

@yellow1912
Copy link
yellow1912 commented Dec 7, 2020

Description
Sometimes we need to share the cache pools among application written in different languages, in my case I cache the redirection rules to Redis, and have my lua script loads them inside nginx to do instant redirection without having to send the request to PHP. Having the cached content serialized by PHP creates lots of unnecessary headaches. Obviously I can skip the whole cache contract by Symfony and save the redirection rules to Redis directly via my custom PHP code, but I would rather not do that if I can.

Right now I cannot see a way to skip serializer (marshaller) or perhaps providing custom serializer per cache pool at all.

Example
I think it can be as simple as:

pools:
      doctrine.system_cache_pool:
        adapter: cache.adapter.redis_doctrine_system
        provider: cache.provider.system_redis
        marshaller: marshaller.nil

or

pools:
      doctrine.system_cache_pool:
        adapter: cache.adapter.redis_doctrine_system
        provider: cache.provider.system_redis
        skip_marshall: true

(I saw this PR: #27484 which is not approved. I think my use case is a bit different however).

Edit 1:

I got around this by defining my own redis adapter and marshaller:


        <service id="cache.adapter.redis_nil_marshaller" class="Symfony\Component\Cache\Adapter\RedisAdapter"
                 abstract="true">
            <tag name="cache.pool" provider="cache.default_redis_provider" clearer="cache.default_clearer"
                 reset="reset"/>
            <tag name="monolog.logger" channel="cache"/>
            <argument/> <!-- Redis connection service -->
            <argument/> <!-- namespace -->
            <argument>0</argument> <!-- default lifetime -->
            <argument type="service" id="cache.nil_marshaller" on-invalid="ignore"/>
            <call method="setLogger">
                <argument type="service" id="logger" on-invalid="ignore"/>
            </call>
        </service>

        <service id="cache.nil_marshaller" class="MyPath\NilMarshaller">
        </service>

@yellow1912 yellow1912 changed the title Allow skipping serializer for a specific cache pool [Cache] Allow skipping serializer for a specific cache pool Dec 7, 2020
@nicolas-grekas
Copy link
Member

Closing as you found the way to do it. This is not common enough to me and we shouldn't add config for that.
Thanks for proposing and for posting your solution.

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

No branches or pull requests

3 participants
0