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

Skip to content

[HttpClient] Add support for configuring cache at framework bundle level #41843

Open
@lyrixx

Description

@lyrixx

Description
ATM, when we want to use cache with the HTTP Client we need to configure it manually like states in the doc.

We can also use the DIC to do so, but I guess this not really easy for new comers

    Symfony\Component\HttpKernel\HttpCache\Store:
        arguments:
            $root: '%kernel.cache_dir%/http-cache'

    opaClientWithCache:
        class: Symfony\Component\HttpClient\CachingHttpClient
        decorates: opaClient
        arguments:
            $client: '@opaClientWithCache.inner'
            $store: '@Symfony\Component\HttpKernel\HttpCache\Store'
            $defaultOptions:
                base_uri: '%env(OPA_ENDPOINT)%'

More over, something is not really DX Friendly: I had to duplication the base_uri as you can see :/

Anyway, having something native in the framework would be much better I think

Example

framework:
    http_client:
        scoped_clients:
            opaClient:
                base_uri: "%env(OPA_ENDPOINT)%"
                headers:
                    Authorization: "Bearer %env(OPA_TOKEN)%"
                cache:
                    enabled: true # This is new, and this add a basic cache in the `cache` dir
                    path: 'foo/bar' # Optional, a location
                    store: @serviceId # Optional, a service for a full control. path and store can not be used at the same time

WDYT?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions