Skip to content

Reset the cached VAT context between requests - #7

Open
loevgaard wants to merge 1 commit into
masterfrom
fix/reset-cached-vat-context
Open

Reset the cached VAT context between requests#7
loevgaard wants to merge 1 commit into
masterfrom
fix/reset-cached-vat-context

Conversation

@loevgaard

Copy link
Copy Markdown
Member

CachedVatContext memoizes the first answer for the lifetime of the service and never clears it.

Under PHP-FPM that is effectively "per request", so nobody notices. Under a worker based runtime — FrankenPHP, RoadRunner, Swoole — the container is kept alive across requests, so the first visitor's VAT choice sticks to the worker and is served to every subsequent visitor. From the shopper's side the toggle button simply stops working.

This makes the context implement Symfony\Contracts\Service\ResetInterface and tags the service with kernel.reset, so Symfony clears the memoized value when it resets the kernel between requests.

symfony/service-contracts is added to require since the interface is now used in src/. It was already installed transitively via symfony/dependency-injection.

Addresses the second bug in #5.

https://claude.ai/code/session_01P9NzuVPQGvaVR97HZFq98a

CachedVatContext memoized the first answer for the lifetime of the service.
Under PHP-FPM that is effectively per request, but worker based runtimes, i.e.
FrankenPHP, RoadRunner and Swoole, keep services alive across requests, so the
first visitor's VAT choice was served to every subsequent visitor and the
toggle appeared to do nothing.

Implement ResetInterface and tag the service with kernel.reset so the cache is
cleared when the kernel is reset between requests.

Claude-Session: https://claude.ai/code/session_01P9NzuVPQGvaVR97HZFq98a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant