on 2018 Oct 07 10:33 PM
I want to add some behaviour to some objects via dynamic attributes. I am also concerned if those attributes are frequently used, then, would calling the attribute handler every time impact the performance? For example, say I want to add an attribute 'isSpecial' to Products which will be calculated on the fly based on some other attributes. If this is to be called every time I add the product to cart, should I move the logic into services (and scatter it at many places) to save over performance (for a heavy object like a cart)?
Should i call the attribute handler like:
public class ProductXXXAttributeHandler implements DynamicAttributeHandler<Boolean, ProductModel> {
@Override
public Boolean get(ProductModel product) {
return product.getExclusiveTill()!=null?product.getExclusiveTill().after(new Date()):false;
}
or should I move this to the Add to cart Strategy, like:
public class XXXCommerceAddToCartStrategy extends DefaultCommerceAddToCartStrategy {
public CommerceCartModification addToCart(CommerceCartParameter parameter) throws CommerceCartModificationException {
...
ProductModel product = paramter.getProduct();
isExclusive = product.getExclusiveTill()!=null?product.getExclusiveTill().after(new Date()):false;
....
}
WHICH ONE WILL BE CONSIDERABLY FASTER?
Request clarification before answering.
You should keep in mind that dynamic attributes are not cached. So, if there are too frequent reads, the performance will be impacted.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I have to use the logic product.getExclusiveTill()!=null?product.getExclusiveTill().after(new Date()):false; just while adding to cnd not anywhere else, I would keep it in the Strategy; otherwise (to make this calculated value of the product attribute reusable at multiple places e.g. for personalization etc.), I would make it dynamic.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.