会话变量未使用新的 cfimage 刷新
至少对我来说,这是一个奇怪的现象。我正在将图像读入 cf 图像变量并将其保存为会话变量:
<cfimage action="read" source="myPath/image.jpg" name="myImage" />
<cfset session.image = #myImage# />
我计划在某个时候操作该图像,这就是我将其保存到变量的原因。不管怎样,然后我用 cfcontent:
<img id="photoPlaceholder" src="/#application.root_name#/administration/PhotoManagement/displayPhoto.cfm" width="500px" />
from template displayPhoto.cfm:
<cfcontent variable="#imageGetBlob(session.image)#" />
来流式传输它,这就是问题所在。第一次调用后,无论传递给哪个新图像,都会显示第一个检索到的图像。我尝试在 cfimage 标记之前销毁会话变量,并且我已经验证每次都传递了正确的图像变量。显示新图像的唯一方法是刷新页面。
在我看来,cfimage 以某种方式缓存图像,并且每次对它的新调用都不会刷新变量 myImage。 CF 文档对此没有任何说明,谷歌也没有提出任何建议。
想法?
Here's an odd one, for me at least. I'm reading an image into a cf image variable and saving it as a session variable:
<cfimage action="read" source="myPath/image.jpg" name="myImage" />
<cfset session.image = #myImage# />
I plan to be manipulating that image at some point, which is why I'm saving it to a variable. Anyway, then I stream it with cfcontent:
<img id="photoPlaceholder" src="/#application.root_name#/administration/PhotoManagement/displayPhoto.cfm" width="500px" />
from template displayPhoto.cfm:
<cfcontent variable="#imageGetBlob(session.image)#" />
Here's the problem. After the first call, the first retrieved image is displayed no matter which new image is passed to it. I've tried destroying the session variable before the cfimage tag, and I've verified that I'm passing the correct image variable each time. The only way a new image is shown is if I refresh the page.
It seems to me that cfimage is somehow caching the image, and each new call to it doesn't refresh the variable myImage. CF documentation says nothing about this, and google brought up nothing.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题可能是客户端的。由于 img 标记中的 URL 不会更改 (...displayPhoto.cfm),因此您的浏览器不会发现您实际上指向新图像,因此它会继续提供缓存中已有的图像。
您可以尝试在 src 属性的末尾添加一个随机的假参数,类似于以下伪代码:
您可以从随机数生成器或时间戳生成器创建 aUniqueValue 变量。
Your problem is probably client-side. Since the URL in your img tag doesn't change (...displayPhoto.cfm), your browser doesn't see that you are in fact pointing to a new image, so it keeps serving up the image already in cache.
You might try adding a randomized fake parameter to the end of your src attribute, something like this pseudo code:
You could create the aUniqueValue variable from a random number generator or timestamp generator.
您还可以在 displayPhoto.cfm 中设置 HTTP 标头,告诉浏览器不要缓存该 URL 中的内容。从理论上讲,这可能会更好,否则浏览器将在每次提供稍微不同的 URL 时保留图像的缓存。在桌面上,这可能不是现实世界的问题,因为桌面上的缓存很大并且不按站点分段,但缓存有限的移动客户端可能会清除您想要缓存的其他内容。
如果图像很大或者相同版本可能会加载很多,请查看 HTTP 标头,否则上面的方法就可以了(我们在我正在开发的应用程序中使用这两种方法)
You could also set the HTTP headers up in displayPhoto.cfm to tell the browser not to cache the content form that URL. In theory, this may be better, as otherwise the browser will keep in cache the image from each time it is given a slightly different URL. that's probably not a real-world concern on a desktop where the cache is large and not segmented by site, but a mobile client with limited cache may purge other content which you'd like cached.
If the image is large or the same version is likely to get loaded a lot, look at the HTTP headers, otherwise the approach above is fine (we use both in the app I work on)