在我们的应用程序中,我们使用 Zend_Db_Row
的子类来表示我们应用程序中的对象。这些对象由各种获取函数返回。
<?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);
}
}
问题是我们从不同的函数、模型、 Controller 等多次调用 fetch 函数(使用相同的值)。例如,$modelUsers->fetchWithEmail('user@domain.com')
在单个 php 脚本执行中出现 10 次。
我们计划使用 memcached 来缓存这些对象,但是,它仍然会调用缓存服务器 10 次(而不是调用数据库 10 次)。使用 memcache 会更快,但我们只想调用缓存服务器一次(而不是 10 次)
zend框架有什么框架/模块可以帮助我们归档某种本地缓存?如果我们的脚本将调用 $modelUsers->fetchWithEmail('user@domain.com')
,它将进入脚本内存,直到脚本执行完成(或者更新或删除函数更改了数据库中该行的值)
最佳答案
Doctrine ORM 实现 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
关于php - Zend_Db_Row 子类的本地 "Cache",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8406540/