简体   繁体   English

如何控制Flex 3图像控件缓存

[英]How to Control Flex 3 Image Control Caching

According to the adobe flex docs: http://livedocs.adobe.com/flex/3/html/help.html?content=controls_15.html 根据adobe flex docs: http//livedocs.adobe.com/flex/3/html/help.html? content= controls_15.html

Using an image multiple times 多次使用图像

You can use the same image multiple times in your application by using the normal image import syntax each time. 每次都可以使用普通图像导入语法在应用程序中多次使用同一图像。 Flex only loads the image once, and then references the loaded image as many times as necessary. Flex仅加载图像一次,然后根据需要多次引用加载的图像。

However, in testing we have found that if you request the same image (same url, etc.) in IE flash 9/10 a new http request will not be issued, but with Firefox, Safari (PC and MAC) a new request is always issued. 但是,在测试中我们发现,如果你在IE闪存9/10中请求相同的图像(相同的网址等),将不会发出新的http请求,但是对于Firefox,Safari(PC和MAC),新的请求是总是发行。

I want to prevent the image from being pulled from the server each time I try and use it anyone have any idea why this is working only in IE? 我想防止每次我尝试使用它时从服务器中提取图像任何人都知道为什么这只在IE中工作?

One workaround is to create your own image cache with ActionScript by saving the BitMapData of the original instance and using it as the source for subsequent instances: 一种解决方法是使用ActionScript创建自己的图像缓存,方法是保存原始实例的BitMapData并将其用作后续实例的源:

private var image1:Image = new Image();    
private var image2:Image = new Image();                 

private function init() : void
{
    image1.addEventListener(Event.COMPLETE, onComplete);
    image1.source = "icon.png";
    addChild(image1);   
}


private function onComplete(event:Event) : void
{   
    var image:Image = event.target as Image;                
    var bitmapData:BitmapData = new BitmapData(image.content.width,
                                               image.content.height, true);    
    bitmapData.draw(image.content);         
    image2.source = new Bitmap(bitmapData);
    addChild(image2);
}

I created a fully functioning example and posted the source here . 我创建了一个功能齐全的示例并在此处发布了源代码。

Here's the answer: NEVER think IE is doing it correctly. 答案就是:永远不要认为IE正确地做到了。 IE was wrong all the other browsers were correct. IE错误所有其他浏览器都是正确的。 The .swf files were being returned with Cache-control: private header. 使用Cache-control:private头返回.swf文件。 IE should NOT have returned the cached image. IE不应该返回缓存的图像。 Setting the Cache-Control header properly resulted in all browsers behaving as expected. 正确设置Cache-Control标头会导致所有浏览器按预期运行。

The best way to load an image a single time and then reuse that image multiple times in a flex application is to embed the image and tie it to a class representation, then just reference that class from then on. 一次加载图像然后在flex应用程序中多次重用该图像的最佳方法是嵌入图像并将其绑定到类表示,然后从那时起引用该类。

Example: 例:

[Embed(source="myImage.jpg")]
[Bindable]
public var myImageClass:Class;

HTH HTH

I've also had success with loading the Image once then reusing it's source property: 我也成功加载了Image然后重用它的source属性:

<mx:Image id="myImage" source='blah.png'/>

var myNewImage:Image = new Image();

myNewImage.source = myImage.source;

The real question isn't how to cache an image, but why does IE use a browser cached image when FF, Safari, Chrome, etc do not? 真正的问题不是如何缓存图像,但为什么IE在FF,Safari,Chrome等不使用浏览器缓存图像? (IE7 btw). (IE7顺便说一句)。

I'm still trying to come up with a reasonable sized example app. 我仍然想要一个合理大小的示例应用程序。 We have a canvas, with a mx:Image or mx:SWFloader. 我们有一个画布,带有mx:Image或mx:SWFloader。 The canvas is recreated, however the image url is identical so the browser should be returning the cached image and not issuing another request for it. 画布被重新创建,但是图像URL是相同的,因此浏览器应返回缓存的图像,而不是发出另一个请求。 A very simple example of just an mx:Image where you set the source, clear the source and reset the source does correctly use the cached image across all browsers. 一个非常简单的mx示例:您设置源,清除源并重置源的图像确实在所有浏览器中使用缓存的图像。

The problem is the Expiration Time of your images. 问题是图像的到期时间。 Configure in the application server the policy for images expiration time and the cache runs OK in all browsers. 在应用程序服务器中配置映像到期时间的策略,并且缓存在所有浏览器中都运行正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM