<?php
require_once 'ItemDaoInterface.php';
class ItemDaoProxy
//class ItemDaoProxy implements ItemDaoInterface
{
private $_dao;
private $_cache;
public function __construct(ItemDaoInterface $dao)
{
$this->_dao = $dao;
$this->_cache = array();
}
public function findById($itemId)
{
if (array_key_exists($itemId, $this->_cache)) {
echo 'Proxyで保持しているキャッシュからデータを返します。<br />';
return $this->_cache[$itemId];
}
$this->_cache[$itemId] = $this->_dao->findById($itemId);
return $this->_cache[$itemId];
}
}