feat(medusa): invalidate price selection caching within update request (#3553)

* feat: invalidate price selection caching on update

* feat: add `onVariantsPricesUpdate` to PriceSelectionStrategy

* fix: update units

* fix: import

* Create .changeset/tame-pillows-heal.md

* fix: address feedback

* refactor: make `onVariantsPricesUpdate` optional

---------

Co-authored-by: fPolic <frane@medusajs.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Frane Polić
2023-03-28 11:18:13 +02:00
committed by GitHub
co-authored by fPolic Oliver Windall Juhl
parent 455c56c4b3
commit 1ce3cc5ae4
10 changed files with 53 additions and 47 deletions
@@ -1,30 +0,0 @@
import { ICacheService } from "@medusajs/types"
import { EventBusService, ProductVariantService } from "../services"
type ProductVariantUpdatedEventData = {
id: string
product_id: string
fields: string[]
}
class PricingSubscriber {
protected readonly eventBus_: EventBusService
protected readonly cacheService_: ICacheService
constructor({ eventBusService, cacheService }) {
this.eventBus_ = eventBusService
this.cacheService_ = cacheService
this.eventBus_.subscribe(
ProductVariantService.Events.UPDATED,
async (data) => {
const { id, fields } = data as ProductVariantUpdatedEventData
if (fields.includes("prices")) {
await this.cacheService_.invalidate(`ps:${id}:*`)
}
}
)
}
}
export default PricingSubscriber