Вы можете создать производную, которая либо расширяет, либо составляет Doctrine_Cache_Memcache .В производной вы просто изменяете id , добавляя доменную часть ключа перед передачей выполнения к Doctrine_Cache_Memcache .
Вот пример, который нужно рассмотреть, используя наследование, переопределяя _doSave метод;другие открытые члены могут быть переопределены аналогичным образом.
<?php
class DomainCache extends Doctrine_Cache_Memcache
{
private function _getDomain()
{
// this could pull from config, a database, it
// could even be hardcoded on a per-project basis - YMMV!
}
/**
* Given the normal id the application would use, prefix
* it with the appropriate domain.
*/
private function _getDomainId($id)
{
return $this->_getDomain() . '_' . $id;
}
/**
* Save a cache record directly. This method is implemented by the cache
* drivers and used in Doctrine_Cache_Driver::save().
* Overridden such that a domain-specific key is used.
*
* @param string $id cache id
* @param string $data data to cache
* @param int $lifeTime if != false, set a specific lifetime for this
* cache record (null => infinite lifeTime)
* @return boolean true if no problem
*/
protected function _doSave($id, $data, $lifeTime = false)
{
return parent::_doSave($this->_getDomainId($id), $data, $lifeTime);
}
}
Если вы заинтересованы в создании Doctrine_Cache_Memcache , например, предположим, что вы хотите расширить то, что обеспечивает реальную работу для _getDomain , вы бы вместо этого внедрили Doctrine_Class_Interface .