php – Magento:Mage :: registry(‘current_product’)效率如何?

栏目: PHP · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/18156609/magento-mageregistrycurrent-product-efficient

如果您知道它背后的过程,这可能是显而易见的.但是当您在产品页面上使用Mage :: registry(‘current_product’)时,您是仅仅引用已经“加载”的内容还是正在加载它每次你运行那行代码?

换句话说,哪个更有效? (下面的伪代码)

Mage::registry('current_product')->getName() over and over

要么…

$temp = Mage::registry('current_product') then
$temp->getName() over and over

调用

Mage::registry('current_product')->getName()

一遍又一遍,效率会略低于

$temp = Mage::registry('current_product') then
$temp->getName() over and over

但是我并不是那么害怕.如果您正在设置编码样式,请选择第二个.如果你有一堆旧的代码与前者,不要担心它的性能.

当您调用Mage :: registry(‘current_product’)时,产品本身不会从数据库重新加载 – 所有这个方法都返回一个存储在Mage类的静态数组上的对象引用.

我说前者效率稍低的原因是,如果你看一下注册表的来源

#File: app/Mage.php
public static function registry($key)
{
    if (isset(self::$_registry[$key])) {
        return self::$_registry[$key];
    }
    return null;
}

你会看到Magento在返回值之前检查是否设置了键.从理论上讲,这种检查是从注册表中获取一次然后重用变量的更多工作.

但是,实际上,在这是一个真正的问题之前,你会遇到更大的瓶颈.

翻译自:https://stackoverflow.com/questions/18156609/magento-mageregistrycurrent-product-efficient


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott、Darron Schall、Keith Peters / Adobe Dev Library / 2006-10-11 / GBP 28.50

Well before Ajax and Microsoft's Windows Presentation Foundation hit the scene, Macromedia offered the first method for building web pages with the responsiveness and functionality of desktop programs......一起来看看 《ActionScript 3.0 Cookbook》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试