fre*_*ent 2 coldfusion loops cfinvoke
我需要遍历一组图像路径来抓取,调整大小并将图像从外部目标存储到S3.
我习惯叫cfcs这样做:
<cfinvoke component="form_img_handler" method="upload" returnvariable="imgSuccess">
<cfinvokeargument name="command" value="upload_search"/>
<cfinvokeargument name="imgPath" value="#results.bildpfad #"/>
<cfinvokeargument name="imgFile" value="#results.bilddateiname#"/>
<cfinvokeargument name="sellerILN" value="#results.iln#"/>
<cfinvokeargument name="cookie" value="#variables.screenWidth#"/>
</cfinvoke>
Run Code Online (Sandbox Code Playgroud)
问题:
如果我必须在循环中执行此操作25x,那么使用cfobject
而不是更好cfinvoke
吗?从我理解cfinvoke
的实例化,运行它的工作和死亡.什么时候cfobjects
留下来.如果是这样,在上述情况下使用会更好cfobject
吗?如果是这样,我将如何调用我的upload
函数(传递参数)以及如何在完成后删除对象?
(从未使用过cfobject ......)
感谢帮助!
Pet*_*ton 10
也不要使用像...这样的东西
外部循环(可能在全局范围内,例如应用程序):
<cfset form_img_hander = createObject('component','dotted.path.to.form_img_hander') />
or
<cfset form_img_hander = new dotted.path.to.form_img_hander() />
Run Code Online (Sandbox Code Playgroud)
内循环:
<cfset imgSuccess = form_img_handler.upload
( command = "upload_search"
, imgPath = results.bildpfad
, imgFile = results.bilddateiname
, sellerILN = results.iln
, cookie = variables.screenWidth
)/>
Run Code Online (Sandbox Code Playgroud)
因为它远远更具可读性.
除非您有可重复的测试用例,证明您存在性能问题,否则您没有性能问题.
关于删除对象...
如果你没有将对象放在持久范围内,你不必担心删除它们 - 它们只与请求绑定,一旦请求结束,它们将根据需要进行垃圾收集.
如果要将对象放在持久范围内,您可能仍然不需要担心删除它们,但如果确定要这样做,则可以使用StructDelete将其删除(就像任何其他变量一样).当然,你应该注意不要在需要的时候这样做.