Hi,
Cache is already implemented in the TaxCloud plugin.
When a cart is loaded, three functions of the plugin are called:
- verifyAddress which get the USPS address from the address entered by the user to make sure that we're dealing with a valid address
- lookup which load the taxes for the products
- onAfterProcessShippings which load the taxes for the shipping methods
In each function, you'll see that the code uses getUserState and setUserState to store and load data to / from the user session so that if a request is the same as one already done, it is skipped and the data in the user session is used instead.
So these functions are called each time a product will be added to the cart, and then when the user enters his address, when he changes his cart content, or modify his address, and then another 2 functions will be called again when the order is created (and maybe one when the order is confirmed).
So that can quickly add up.
While the taxes might not be needed on your website before the customer access the cart, that might be different for someone else. If the customer is already logged in with a user with an address and he adds something in the cart, if the cart module is displayed on the page where the customer adds a product in the cart, and the cart module is configured to display taxes, it needs the taxes to be calculated. Or if the merchant is using the "shipping estimation" plugin so that the customer can get the shipping price on the product page while the shipping methods are taxed and he wants to display the shipping prices with taxes.
Thinking about it, I suppose some code could be added to the plugin to skip when the user didn't login or fill in the guest form yet.
Try adding the code:
if(!hikashop_loadUser(false))
return false;
just after the lines:
protected function lookup(&$cart) {
and:
protected function verifyAddress() {
If that helps, we could add an option to skip the calls before the user login or fill in the guest form