Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable as3 caching

I have an AS3 application running in flash player which aims at refreshing an image stored on a server. On every 1 second, the server replaces the image by a new one.

To get the image from server and not from cache, I had to add to use the random number method as shown below:

loader = new URLLoader();
var request:URLRequest = 
new URLRequest(
   "http://www.theServer.com/myImage.png?random"+(Math.random() * 10000));
loader.load(request);

, and the whole refreshing process works.

But what is annoying is that this method generates temporary files in the temporary folder which is growing and growing:

C:\Users\MyName\AppData\Local\Microsoft\Windows\INetCache

Is there a way to disable the cache as it is possible to do with Air? I am asking this because the application is to run on an embedded platform with flash player 10, on which there might be no way to access to flash player settings.

Regards.

like image 944
wangson200 Avatar asked Jan 27 '15 11:01

wangson200


1 Answers

Thanks for the hint Vesper, I finally found one way to disable cache for both AIR and actionscript:

    function loadURLWitoutCaching(theURL:String):void
    {
        var _imgLoader:Loader       = new Loader();
        _imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
        _imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoadingError);

        var header:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
        var request:URLRequest = new URLRequest(theURL);
        request.data = new URLVariables("cache=no+cache");
        request.method = URLRequestMethod.POST;
        request.requestHeaders.push(header);
        try {
            _imgLoader.load(request);
        } catch (error:Error) {
            trace("Unable to load requested document.");
        }
    }

    private function onLoadingError(e:IOErrorEvent):void
    {
        // Do something
    }

    private function onLoadComplete(evt:Event):void
    {
        // Do something
    }

I am not sure the "URLVariables" is mandatory but it seemed to help.

Now I can't see any more mages being cached in "C:\Users\myName\AppData\Local\Microsoft\Windows\INetCache" folder.

Have a good day.

like image 166
wangson200 Avatar answered Nov 04 '22 23:11

wangson200