I'm rewriting shopping cart for my application. My current thinking of cart is:
Two model classes:
Invoice which can have many items in it and
Item which has one invoice, and a Singleton class
Cart for managing items in selected invoice, which stores ordered Items in session as array of records and a link to Invoice which currently in cart.
It works like:
Cart::getInstance()->getItems(); Cart::getInstance()->putItem($itemCode, $qty); Cart::getInstance()->removeItem($itemCode); Cart::getInstance()->save()
During operation with cart it stores items as array of records in session. All changes are written to database on save only.
$cart = Invoice::find([ 'conditions'=>"user_id = :own_id: and invoice_number = :inv_num:", 'bind' => ['own_id'=>static::$ownerId,'inv_num'=>static::$invNum], 'limit' => 1 ])->getFirst(); $cart -> InvoiceItems = static::$cartItems; static::$cartInstance->save();
This works nice in test environment, however because I'm storing the whole records in session, I doubt if this is best solution. I haven't much experience with storing large session variables, but I know they do affect performance.
So, is there a better way to store Phalcon's result set, if don't want changes to be immediately written to database? (tmp database, toarray, caching, transactions?)
Any way to measure perfomance impact?