DylanD

Caching Resources

Recommended Posts

Hey everyone,

I was curious if my understanding of how babylonjs and resources work with caching.  The way i understand it works is that if I load a resource it becomes cached until that page is reloaded/cache is emptied.  I think that it works this way for all of the resource types I am using (sound files, scene files/models, textures, and images).  

However I looked into it a bit and read this doc https://doc.babylonjs.com/how_to/caching_resources_in_indexeddb

Which makes me think that the resources are only cached if I declare it so in the manifest files.  However this is an older version of babylonjs so maybe it is outdated?

I also read this 

Which makes me a bit more confused, however it seems that the manifest is for .babylons only,  or could i put that on all the files?

So I was wondering is my understanding of how babylonjs caches, incorrect?

How does babylonjs cache things (sound files, scene files/models, textures, and images)?

If so do i just need to add a .manifest file to each resource I want cache?

 

Any Ideas?

Share this post


Link to post
Share on other sites

To add on.  In my game i have tested, loading textures into a array, then also in the same scene, loading the texture again and when i load it the second time its almost instant, making me think it is already cached.  Not sure where i read that it worked like that though.  But it correlates with my testing.

Share this post


Link to post
Share on other sites

Hello, so there are different levels of caching. The second one you mentioned is the engine cache. All texture contents are cached by the engine so if you load the same texture twice, it will be instant (and resource will be shared to save memory).

There is also a cache per browser (the IndexedDB one). This one is controlled by the manifest file. If no manifest, there is no caching

Share this post


Link to post
Share on other sites
On 10/2/2018 at 11:58 AM, Deltakosh said:

Hello, so there are different levels of caching. The second one you mentioned is the engine cache. All texture contents are cached by the engine so if you load the same texture twice, it will be instant (and resource will be shared to save memory).

There is also a cache per browser (the IndexedDB one). This one is controlled by the manifest file. If no manifest, there is no caching

Thanks!, thats pretty cool.  So as long as i dont have multiple engines or switch engines I can use engine caching.  So are only texture contents cached by the engine?  if so is there a way i could force the engine to cache other resources like sounds and models, or would that be done by the browser caching?   

Also if i had to use browser caching i would just need to add "$name.manifest" to my resources folder and  add this to each .manifest

{
  "version" : 1,
  "enableSceneOffline" : true,
  "enableTexturesOffline" : true
}

Then whenever i try to load the resource it should load instantly or at least super fast. 

Sorry im very curious about this as i try to make my game a bit faster with loading, by caching.

Thanks!

Share this post


Link to post
Share on other sites
21 hours ago, V!nc3r said:

 @Deltakosh, sorry for the raw copy-paste 😄

@DylanD, do not be sorry to ask questions. On the contrary, if the doc' is not clear, you have to ask without hesitation (and the doc' have to be updated :) )

So it would seem i can only cache texture files with the engine.   

So for browser caching, as long as  i make a .manifest file i can cache anything right?  

ie,

Sound files

Models

Shaders(not sure if they are even worth caching since they are small but still curious)

Can these^ also be cached with a simple manifest file?

Thanks for the help you guys !!

Share this post


Link to post
Share on other sites

Hey guys, looking into caching again, i was wondering https://doc.babylonjs.com/how_to/caching_resources_in_indexeddb this doc says as of Babylonjs V4.0 we use 

BABYLON.IDBStorageEnabled = true;

I was wondering if this is in 4.0.0-alpha.8 or if it was meant for when V4.0 is in a release build, as it does not seem to be in 4.0.0-alpha.8

If it is what am i doing wrong?

I put that line of code at the very start of my code and it says it doesnt exist on type babylonjs.  I have also tried other areas of my code and it doesnt work there either.

 

How am i supposed to use

 BABYLON.IDBStorageEnabled = true;

Share this post


Link to post
Share on other sites

I was also wondering that doc mentions that I need to add a .manifest to my scene ("To enable offline support, the first thing you need to do is create a .manifest file associated with your scene. It should be named NameOfYourScene.babylon.manifest."   ), however my main scenes are not saved as .babylon's(or saved at all for that matter), they are initialized in code as they are basic/procedurally generated.  How will this impact my ability to to cache other things such as sound files?

From my understanding i should be able to cache them still.  

Share this post


Link to post
Share on other sites
19 hours ago, Deltakosh said:

Doc is wrong :) (I'll fix it)

Please use BABYLON.Database.IDBStorageEnabled = true;

Regarding the caching of your files, this should not be a problem (you can also just use engine.disableManifestCheck = true to avoid the manifest check)

Thanks!

with the engine.disableManifestCheck = true i dont need to make manifest files for all my files?

Or is that just for the scene one ?

Share this post


Link to post
Share on other sites

Even after writing manifests I am not able to cache the .mtl files of my models.

My manifest file is:

{
  "version" : 1,
  "enableSceneOffline" : true,
  "enableTexturesOffline" : true
}

the .obj files of my custom made models are cached, but not my .mtl files of the models.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.