Skip to content

Cache generation issues #76

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

Open
vvasiloi opened this issue Jun 20, 2022 · 0 comments
Open

Cache generation issues #76

vvasiloi opened this issue Jun 20, 2022 · 0 comments

Comments

@vvasiloi
Copy link

Hi,

While integrating the plugin together with the providers added in #63, we encountered some issues with the caching mechanism:

  1. Enabling the cache completely breaks the provider because in our checkout flow there's no shipping address at that point.
    The customers first enter the billing address, then they either add a shipping address or select a pickup point based on the billing address. Ref:
    private function buildOrderCacheKey(OrderInterface $order): string
    {
    $shippingAddress = $order->getShippingAddress();
    if (!$shippingAddress instanceof AddressInterface) {
    throw new RuntimeException(sprintf(
    'Shipping address was not found for order #%s',
    $order->getNumber()
    ));
    }
  2. It completely breaks because the exceptions thrown during the cache key generation are not caught
  3. Because the cache key generation is in private methods, changing that logic would mean copy-pasting the entire class and replacing the service.
  4. The CacheProvider decorators have a relatively high priority of 256, which created a bit of confusion because we already decorated the providers with the default priority of 0.

To overcome all these issues, I suggest the following changes:

  1. Extract the cache key generation logic in separate classes, so it's easy to change per project or even per provider.
  2. Catch errors from cache key generation, log them and bypass the cache.
  3. Register the cache decorators with a negative priority.
  4. Fallback to the billing address when there's no shipping address on cache key generation.

WDYT?

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

No branches or pull requests

2 participants