shopware icon indicating copy to clipboard operation
shopware copied to clipboard

feat: enable store api routes caching

Open h1k3r opened this issue 3 months ago • 5 comments

1. Why is this change necessary?

For StoreAPI performance improvement, part of routes should support http caching.

2. What does this change do, exactly?

  • Marks a number of StoreAPI routes for caching;
  • Changes CacheResponseSubscriber to add proper Cache-Control header to the StoreAPI routes marked for caching
  • Adds support of cache policies and allows to specify cache-control policies on global/local level.

3. Describe each step to reproduce the issue or behaviour.

  • Enable caching using reverse proxy, like
    http_cache:
        reverse_proxy:
            enabled: true
            use_varnish_xkey: true
            hosts:
                # address to this varnish container or all varnish containers
                - localhost
  • Call endpoint that supports caching:
curl -i --location 'http://localhost:8000/store-api/category?limit=10' \
--header 'sw-access-key: YOUR_STOREFRONT_API_ACCESS_KEY' 

4. Please link to the relevant issues (if any).

  • closes https://github.com/shopware/shopware/issues/12391

5. Checklist

  • [x] I have written tests and verified that they fail without my change
  • [ ] I have created a changelog file with all necessary information about my changes
  • [ ] I have written or adjusted the documentation according to my changes
  • [x] This change has comments for package types, values, functions, and non-obvious lines of code
  • [ ] I have read the contribution requirements and fulfilled them

h1k3r avatar Sep 08 '25 12:09 h1k3r

Warnings
:warning: You updated the shopware.yaml, please consider to update the config-schema.json

github-actions[bot] avatar Sep 08 '25 12:09 github-actions[bot]

part of routes should support http caching (at least on the reverse proxy side).

Just wondering it is not only reverse proxy cache, default symfony http caching should work as well correct?

keulinho avatar Oct 15 '25 11:10 keulinho

📸 OpenAPI Snapshot

ℹ️ No changes detected compared to trunk

🔗 Base Branch Snapshot: https://explore-openapi.dev/view?project=shopware-store-api&snapshot=trunk

github-actions[bot] avatar Oct 24 '25 15:10 github-actions[bot]

OpenAPI Snapshot

Project: shopware/store-api

No changes detected

Your OpenAPI schema is identical to the base branch (trunk).

Links:
All Project Snapshots · Base Branch Snapshot

Project: shopware/admin-api

No changes detected

Your OpenAPI schema is identical to the base branch (trunk).

Links:
All Project Snapshots · Base Branch Snapshot

explore-openapi[bot] avatar Nov 05 '25 15:11 explore-openapi[bot]

Codecov Report

:x: Patch coverage is 80.47138% with 58 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 54.03%. Comparing base (62aa6ee) to head (692b168). :warning: Report is 2 commits behind head on trunk. :white_check_mark: All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...re/Framework/DependencyInjection/Configuration.php 81.08% 14 Missing :warning:
...ramework/Script/Api/ResponseCacheConfiguration.php 0.00% 10 Missing :warning:
src/Storefront/Controller/ScriptController.php 0.00% 7 Missing :warning:
...ontent/Category/SalesChannel/CategoryListRoute.php 0.00% 5 Missing :warning:
...egory/SalesChannel/TreeBuildingNavigationRoute.php 0.00% 5 Missing :warning:
src/Core/Content/Seo/SalesChannel/SeoUrlRoute.php 0.00% 5 Missing :warning:
...ore/System/Currency/SalesChannel/CurrencyRoute.php 0.00% 5 Missing :warning:
...ore/System/Language/SalesChannel/LanguageRoute.php 0.00% 5 Missing :warning:
...ork/Adapter/Cache/Http/CacheResponseSubscriber.php 98.07% 1 Missing :warning:
.../Core/Framework/Script/Api/ScriptStoreApiRoute.php 0.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #12370      +/-   ##
==========================================
+ Coverage   53.97%   54.03%   +0.06%     
==========================================
  Files        3189     3193       +4     
  Lines       95733    95970     +237     
==========================================
+ Hits        51669    51856     +187     
- Misses      44064    44114      +50     
Flag Coverage Δ
phpunit-migration 94.31% <ø> (ø)
phpunit-unit 51.92% <80.47%> (+0.06%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 06 '25 16:11 codecov[bot]