Skip to content

Document cart totals caching (spec 0076) - #50

Open
glennjacobs wants to merge 1 commit into
nextfrom
docs/cart-totals-caching
Open

glennjacobs wants to merge 1 commit into
nextfrom
docs/cart-totals-caching

Conversation

@glennjacobs

Copy link
Copy Markdown
Collaborator

Summary

Companion to lunarphp/lunar#2721, which implements spec 0076 (cart totals caching in the database). Documents the persisted totals snapshot on the v2 carts pages and the behaviour changes downstream code needs to know about.

Changes

  • 2.x/reference/carts.mdx — snapshot columns added to the Cart (15) and CartLine (9) field tables in schema order; the overview callout no longer says totals are not stored; calculate() now documented as memo, then fresh snapshot, then pipeline, with recalculate() for guaranteed-fresh totals; new Persisted totals section (freshness rule, lunar.cart.totals.ttl, totalsAreFresh() / invalidateTotals(), total column shadowing) and Invalidation section (per-change mechanism table, write guard, activity-log exclusion); setCurrency() wording updated to the refresh behaviour.
  • 2.x/extending/carts.mdxCalculatesCart, HydratesCartTotals, PersistsCartTotals added to the contract table; new Totals caching section explaining that persistence lives in the action rather than a pipe, with a rebinding example that switches the snapshot off, and a warning about query-builder writes needing invalidateTotals().
  • 2.x/extending/payments.mdx — the amount guard example reads the cart through recalculate(), with the reasoning.
  • 2.x/guides/cart.mdx — the "calculated on demand" callout now points at the persisted totals section.
  • 2.x/getting-started/overview/upgrade-guide.mdxadd_cart_totals_columns data migration listed; manual checklist item for calculate() possibly serving persisted totals and updateLine() now firing model events.
  • 2.x/getting-started/setup/system-settings.mdxconfig/lunar/cart.php purpose mentions the totals TTL.

No new pages, so docs.json is unchanged.

Verification

  • mint validate passes (strict build).
  • mint broken-links passes.
  • The CalculateCartWithoutSnapshot example was run against the monorepo branch in a throwaway Pest test: the rebinding calculates the cart and leaves total / calculated_revision null on the row.
  • Column names, order, casts, config key and method names checked against lunarphp/lunar feat/cart-totals-caching.

Should merge after lunarphp/lunar#2721.

🤖 Generated with Claude Code

Companion to lunarphp/lunar#2721 (spec 0076). Adds the persisted totals
snapshot columns to the Cart and CartLine field tables, documents the
calculate() decision order, the freshness rule, lunar.cart.totals.ttl,
invalidation paths, the write guard and the total column shadowing, and
covers the new CalculatesCart / HydratesCartTotals / PersistsCartTotals
contracts with a rebinding example. Payment drivers read totals through
recalculate(). Upgrade guide gains the data migration and the behavioural
note for calculate() and updateLine().

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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