Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local "Cache" for Zend_Db_Row subclasses

Across our application, we use subclasses of Zend_Db_Row to represent objects in our application. these objects are being returned by various fetch functions.

<?php
require_once 'Zend/Db.php';

class Model_Users extends Zend_Db_Table_Abstract
{
    protected $_name = 'users';
    protected $_primary = 'userId';
    protected $_rowClass = 'Model_User';

    /**
     * fetch user by email
     * 
     * @param string $email
     */
    public function fetchWithEmail($email)
    {
        $select = $this->select();
        $select->where('email = ?', $email);
        return $this->fetchRow($select);
    }

}

The issue is that we call the fetch functions multiple times (with the same values) from different functions, models, controllers and such. so for example, $modelUsers->fetchWithEmail('[email protected]') appears 10 times in a single php script execution.

We are planning on using memcached for caching these objects, however, it would still call the cache server 10 times (instead of calling the database 10 times). using memcache will be faster, but we want to call the cache server only once (instead of 10 times)

Any framework / module of zend framework that can help us archive some kind of local cache? That if our script will call $modelUsers->fetchWithEmail('[email protected]'), it would enter the script memory until the script execution was completed (or either an update or delete function changed the value of that row in the database)

like image 762
aporat Avatar asked May 11 '26 00:05

aporat


1 Answers

Doctrine ORM implements EntityManager.

The EntityManager API is used to manage the persistence of your objects and to query for persistent objects.

http://www.doctrine-project.org/docs/orm/2.1/en/reference/architecture.html#the-entitymanager

like image 185
Alex Avatar answered May 12 '26 16:05

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!