开发者

Session variable not refreshing with new cfimage

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?


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:

<img id="photoPlaceholder" src="/#application.root_name#/administration/PhotoManagement/displayPhoto.cfm?somevar=#aUniqueValue#" width="500px" />

You could create the aUniqueValue variable from a random number generator or timestamp generator.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜