Disable as3 caching

I have an AS3 application running in a flash player that is designed to update an image stored on a server. Every 1 second, the server replaces the image with a new one.

To get the image from the server, and not from the cache, I had to add a 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 update process works.

But what is annoying is that this method creates temporary files in a temporary folder that grows and grows:

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

Is there any way to disable the cache, how is this possible to do with Air? I ask about this, because the application should run on the built-in platform with a flash player 10, on which there can be no access to the player settings.

Sincerely.

+5
source share
1 answer

Thanks for the help from Wesper. Finally, I found one way to disable the cache for 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'm not sure that "URLVariables" is required, but it seems to have helped.

Now I do not see any more cache caches in the folder "C: \ Users \ myName \ AppData \ Local \ Microsoft \ Windows \ INetCache".

Have a nice day.

+8
source

Source: https://habr.com/ru/post/1211996/


All Articles