stop/start seems to break cache

3 views
Skip to first unread message

makc

unread,
Oct 17, 2009, 5:16:35 AM10/17/09
to masapi
I have to do stop/start calls in order to be able to add new files
aftert I start loading stuff. However, this seem to cause masapi to
load previously files again (I mean in case when I add the file with
the same url). I wrote the wrapper and worked around problem there,
but isn't masapi supposed to solve this transparently?

Cédric Tabin

unread,
Oct 17, 2009, 5:23:55 AM10/17/09
to mas...@googlegroups.com, makc.th...@gmail.com
Hello,

The way how masapi works is that when a file is loaded, the Massloader forget about it (but not the CompositeMassLoader !). When the Massloader is stopped, all the files that are not yet fully loaded are keeped in the loading queue. Once you have added your files and restarted the Massloader, it will relaunch the the loading process on every file in the loading queue.
For the files with the same url, that's quite hard to keep all the instances (in the factory I mean), and check if the same file is asked... so when you add a file by CML.addFile(), that will create a new instance of ILoadableFile and add it in the Massloader.

How did you expect it to work ? Maybe I misunderstood your question :-)

Best regards,
Cedric

ps. Please subscribe to the googlegroup :-)

makc

unread,
Oct 17, 2009, 5:33:38 AM10/17/09
to masapi
well, what I have now is two situations, 1st

-load some file
-load some file
-load file x
-load some file
-file x loaded
-load some file
-load file x: here it is loaded again regardless file.useCache setting
(what is it even for btw), would be cool if it just fired progress/
complete events but returned already loaded thing in getData,
actually;

2nd,

-load some file
-load some file
-load file x
-load some file
-load some file
-load file x: although previous x is not yet loaded, there is no
reason to load it twice, instead, why doesnt masapi just wait for 1st
x, and then reports both files loaded?

I had to write extra code to handle both situations, which kinda
defeats the purpose of using masapi in 1st place.

Cédric Tabin

unread,
Oct 17, 2009, 5:39:17 AM10/17/09
to mas...@googlegroups.com
Hi,

The useCache value acts as following : when false, if will add a noCache variable to the file url in order to force the player to reload the file. Otherwise, nothing happen. If the ILoadableFile bytesTotal and bytesLoaded are the same, the file won't be reloaded...
Maybe can you show me some piece of code you're using.

Regards,
Cedric

Makc

unread,
Oct 17, 2009, 5:46:21 AM10/17/09
to mas...@googlegroups.com
On Sat, Oct 17, 2009 at 12:39 PM, Cédric Tabin <tabin....@gmail.com> wrote:
> Hi,
>
> The useCache value acts as following : when false, if will add a noCache
> variable to the file url in order to force the player to reload the file.
> Otherwise, nothing happen. If the ILoadableFile bytesTotal and bytesLoaded
> are the same, the file won't be reloaded...

well, surprisingly it does. maybe it is server-browser-flash problem
that it doesnt actually put file in cache, but - as end user of
masapi, in this case - why should I care? I want my files to be loaded
once even if cache doesnt work, and if I can enforce this in my code,
so can you in yours.

> Maybe can you show me some piece of code you're using.
>

I used 1st cml.addFile from examples, and then I expanded it into

var file:ILoadableFile = cml.createFile(url, LoadableFileType.SWF,
null, null, onLoaded);/// file.useCache = false;
(cml.massLoader as PriorityMassLoader).addPrioritizedFile (file, priority);
if (cml.massLoader.stateLoading) cml.massLoader.stop ();
cml.massLoader.start ();

in order to play with file.useCache, so now cml isn't really used.

Cédric Tabin

unread,
Oct 17, 2009, 5:52:49 AM10/17/09
to mas...@googlegroups.com
Hi,

Regarding your answer, you say that the useCache of the file is false, so it is normal that masapi will reload the file... You have to let this value to true if you don't want that behavior...

Regards,
Cedric

Makc

unread,
Oct 17, 2009, 5:53:44 AM10/17/09
to mas...@googlegroups.com
On Sat, Oct 17, 2009 at 12:52 PM, Cédric Tabin <tabin....@gmail.com> wrote:
> Regarding your answer, you say that the useCache of the file is false, so it
> is normal that masapi will reload the file... You have to let this value to
> true if you don't want that behavior...
>
gmail doesnt highlight the code, so you didnt notice that it is commented out.

Cédric Tabin

unread,
Oct 17, 2009, 5:57:35 AM10/17/09
to mas...@googlegroups.com
Re,

Okay I thaught that it was to indicate the useCache value. So what about your file ? You're creating it, adding it in the massloader, stop the massloader and restart it. It will be loaded, isn't it ?
In order to know if a ILoadableFile must be reloaded or not, Masapi does the following checks :
- if useCache is false => reload
- if url has changed => reload
- if bytesTotal is no known => reload
- if bytesLoaded < bytesTotal => reload

Regards,
Cedric

Makc

unread,
Oct 17, 2009, 6:02:19 AM10/17/09
to mas...@googlegroups.com
On Sat, Oct 17, 2009 at 12:57 PM, Cédric Tabin <tabin....@gmail.com> wrote:
> Re,
>
> Okay I thaught that it was to indicate the useCache value. So what about
> your file ? You're creating it, adding it in the massloader, stop the
> massloader and restart it. It will be loaded, isn't it ?

yes. and that's the problem. are you saying that using cml.addFile
would work differently?

> In order to know if a ILoadableFile must be reloaded or not, Masapi does the
> following checks :

> [snip]


> - if bytesLoaded < bytesTotal => reload

the last check, in particular, makes no sense - why would you want to
restart anything that is already loading?

Cédric Tabin

unread,
Oct 17, 2009, 6:09:03 AM10/17/09
to mas...@googlegroups.com
Hi,

Firstly, a new ILoadableFile just created and added in a MassLoader will always be loaded... I don't see why this behavior isn't correct to you ?
And the last check is necessary because there is no way to manage the cache of the FlashPlayer... maybe when you call a load on a URLoader that is already 75% loaded, the FP will begin where it was or reload the whole stuf. Who knows ? So it is implementation-dependant and that force you to recall the load method on the object (and thus relaunch the loading of the file in masapi).

Regards,
Cedric

Makc

unread,
Oct 17, 2009, 6:26:20 AM10/17/09
to mas...@googlegroups.com
On Sat, Oct 17, 2009 at 1:09 PM, Cédric Tabin <tabin....@gmail.com> wrote:
> Hi,
>
> Firstly, a new ILoadableFile just created and added in a MassLoader will
> always be loaded... I don't see why this behavior isn't correct to you ?

I'm not saying that it behaves contrary to its design ( that would be
a bug report).
I'm saying that it doesnt work to solve my problem :)

> And the last check is necessary because there is no way to manage the cache
> of the FlashPlayer... maybe when you call a load on a URLoader that is
> already 75% loaded, the FP will begin where it was or reload the whole stuf.
> Who knows ? So it is implementation-dependant and that force you to recall
> the load method on the object (and thus relaunch the loading of the file in
> masapi).

Yeah, well, I would be happy not to call stop/start but then again I
cannot add files unless I restart everything.

Cédric Tabin

unread,
Oct 17, 2009, 6:41:30 AM10/17/09
to mas...@googlegroups.com
Re,

Maybe can you handle the things differently ? Waiting to the massload complete before adding new files and then restart... I don't know what's your design. Did you have a look on the ApplicationMassloader ?

Regards,
Cedric

Makc

unread,
Oct 17, 2009, 6:56:14 AM10/17/09
to mas...@googlegroups.com
On Sat, Oct 17, 2009 at 1:41 PM, Cédric Tabin <tabin....@gmail.com> wrote:
> Re,
>
> Maybe can you handle the things differently ? Waiting to the massload
> complete before adding new files and then restart... I don't know what's
> your design.

I have a bunch of images that are going to be loaded randomly on
"whenever the need comes" basis. So every time when an object that
requires this image is created, I simply call static function that
adds this object to "queue" for loading, and updates it with loaded
image at some point later. Same class is used by global preloader to
display itself when something is loading. I'm sure there will be oop
gurus saying this design is bad, but it keeps my code extremely simple
and makes me happy. However, in this class I now also have to track
all previous requests and filter duplicates before passing it to
masapi. I sorta hoped masapi does this for me, but it doesnt, that's
all I'm saying.


> Did you have a look on the ApplicationMassloader ?
>

nah, I only checked basic stuff on wiki and relevant things in
reference. Is there an article about ApplicationMAssLoader I missed?

Cédric Tabin

unread,
Oct 17, 2009, 7:08:23 AM10/17/09
to mas...@googlegroups.com
Re,

Maybe the ApplicationMassLoader would be useful for your needs : You just have to declare your pictures in an xml with an id and then you can simply retrieve it with an ApplicationContext. Currently, there is no real documentation about that with masapi 2.0... just the asdoc. If you don't have problem with that, you can look at the package ch.capi.net.app. And you'll find the full XML specification here. That will allow you to bypass the check of a duplicate of your files :-)

Best regards,
Cedric
Reply all
Reply to author
Forward
0 new messages