使用Doctrine时,我发现我有很多通过Doctrine到我的Redis服务器的检索请求,这些请求要求类元数据。 因此,我选择了一个自定义CacheProvider并重写了doFetchMultiple函数。但是ClassMetadata调用永远不会达到此功能。 我以为如果我执行“ addSelect”原则,则现在将需要此类元数据并执行doFetchMultiple。 因此,我想知道是否有可能告诉Doctrine它应该使用fetchMultiple加载此ClassMetadata吗?
class CacheProvider extends \Doctrine\Common\Cache\CacheProvider
{
const CACHE = 'cache';
/**
* Fetches an entry from the cache.
*
* @param string $id The id of the cache entry to fetch.
*
* @return mixed|false The cached data or FALSE, if no cache entry exists for the given id.
*/
protected function doFetch( $id )
{
//i always land here !!!!?
return Cache::get($id, self::CACHE);
}
/**
* Tests if an entry exists in the cache.
*
* @param string $id The cache id of the entry to check for.
*
* @return bool TRUE if a cache entry exists for the given cache id, FALSE otherwise.
*/
protected function doContains( $id )
{
return Cache::exists($id, self::CACHE);
}
/**
* Puts data into the cache.
*
* @param string $id The cache id.
* @param string $data The cache entry/data.
* @param int $lifeTime The lifetime. If != 0, sets a specific lifetime for this
* cache entry (0 => infinite lifeTime).
*
* @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
*/
protected function doSave( $id, $data, $lifeTime = 0 )
{
return Cache::set($id, $data, $lifeTime, self::CACHE);
}
/**
* Deletes a cache entry.
*
* @param string $id The cache id.
*
* @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise.
*/
protected function doDelete( $id )
{
return Cache::delete($id, self::CACHE);
}
/**
* Flushes all cache entries.
*
* @return bool TRUE if the cache entries were successfully flushed, FALSE otherwise.
*/
protected function doFlush()
{
return Cache::flush(self::CACHE);
}
/**
* Retrieves cached information from the data store.
*
* @since 2.2
*
* @return array|null An associative array with server's statistics if available, NULL otherwise.
*/
protected function doGetStats()
{
return Cache::getStats(self::CACHE);
// TODO: Implement doGetStats() method.
}
protected function doFetchMultiple( array $keys )
{
return Cache::getMultiple($keys, self::CACHE);
}