Skip to content

[HttpCache] Explain how to extend the HttpCache class #17972

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

Merged
merged 1 commit into from
Mar 2, 2023

Conversation

HypeMC
Copy link
Member

@HypeMC HypeMC commented Feb 26, 2023

Followup to #16402.

In versions of Symfony prior to 5.4 the caching kernel was enabled by wrapping the default kernel into it inside the front controller, eg:

// public/index.php
use App\CacheKernel;
use App\Kernel;

// ...
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
// Wrap the default Kernel with the CacheKernel one in 'prod' environment
if ('prod' === $kernel->getEnvironment()) {
    $kernel = new CacheKernel($kernel);
}

Starting from version 5.4 this was changed to be done through the configuration:

# config/packages/framework.yaml
when@prod:
    framework:
        http_cache: true

However, it was never explained how the caching kernel can be extended in this case. Decorating the http_cache service seems like the best option.

@carsonbot carsonbot added this to the 5.4 milestone Feb 26, 2023
@OskarStark OskarStark changed the title [HttpCache] Explain how to extend the HttpCache class [HttpCache] Explain how to extend the HttpCache class Feb 27, 2023

.. configuration-block::

.. code-block:: yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see a follow up PR against 6.2 adding how this can be done using an attribute 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see #17975.

@OskarStark
Copy link
Contributor

Thank you @HypeMC.

@OskarStark OskarStark merged commit e217f00 into symfony:5.4 Mar 2, 2023
@HypeMC HypeMC deleted the explain-how-to-extend-the-httpcache branch March 2, 2023 08:33
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Mar 2, 2023
This PR was merged into the 6.2 branch.

Discussion
----------

[HttpCache] Add example with an attribute

Followup to symfony#17972.

Adds an example using an attribute.

Commits
-------

e992925 [HttpCache] Add example with an attribute
javiereguiluz added a commit that referenced this pull request Mar 16, 2023
…eMC)

This PR was merged into the 5.4 branch.

Discussion
----------

[HttpCache] Fix decorating `http_cache` xml example

Followup to #17972 . The xml example is missing the `<services>` tag.

Commits
-------

6641fa5 [HttpCache] Fix decorating http_cache xml example
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.

3 participants