//Mage_Core_Model_App
public function useCache($type=null)
{
return $this->_cache->canUse($type);
}
//Mage_Core_Model_Cache
public function canUse($typeCode)
{
// _allowedCacheOptions为空
if (is_null($this->_allowedCacheOptions)) {
$this->_initOptions();
}
if (empty($typeCode)) {
return $this->_allowedCacheOptions;
} else {
if (isset($this->_allowedCacheOptions[$typeCode])) {
return (bool)$this->_allowedCacheOptions[$typeCode];
} else {
return false;
}
}
}
protected function _initOptions()
{
// OPTIONS_CACHE_ID->core_cache_options 这里首先从缓存中获取这个值
$options = $this->load(self::OPTIONS_CACHE_ID);
if ($options === false) { //没有获取值
//从数据库获取值
$options = $this->_getResource()->getAllOptions();
if (is_array($options)) {
$this->_allowedCacheOptions = $options;
//把值缓存起来
$this->save(serialize($this->_allowedCacheOptions), self::OPTIONS_CACHE_ID);
} else {
$this->_allowedCacheOptions = array();
}
} else {
//取到了值
$this->_allowedCacheOptions = unserialize($options);
}
if (Mage::getConfig()->getOptions()->getData('global_ban_use_cache')) {
foreach ($this->_allowedCacheOptions as $key => $val) {
$this->_allowedCacheOptions[$key] = false;
}
}
return $this;
}