Generate optimised cache file name based on parametric object properties?

This is more of a general javascript question but I figured someone here would have some good ideas.

Say I have an instance of a parametric object, a dining table, defined by the JSON:

{ width: "2", height: "0.7", depth: "1.2", legProfile: "square", legMaterial: "pine01", topProfile: "rounded", topMaterial: "walnut01" }

And I want to create and store a cached, static version of this object using a short as possible hash file name e.g.


… such that I can decode/inflate the hash file name to a parametric object again or simply find the static cache object based on its parameters, as efficiently as possible. Assume parameter order is fixed.

What’s the best approach? Does Babylon.js have anything like this inbuilt for its own caching?

Pinging @syntheticmagus to see if he has any thoughts on this.

1 Like

Hi inteja,

I don’t know of anything like this built into Babylon.js. If I’m understanding what you’re asking about, it seems the serialization would be pretty specific to the scenario. For the string fields in your JSON, is there an unvarying finite set of legal values they can hold? For example, are there only 100 topMaterials? If so, probably the easiest/shortest serialization mechanism I can think of would be to just represent the bytes.

In your provided example, your first three fields are all floating point values, so to fully represent that you’d need 12 bytes, probably represented as 24 characters representing the hex to be sure to safely avoid illegal file name characters. You could find ways to get by with less, but you’d have to be careful to make sure you could represent all allowable values. For the remaining fields, you could represent them using the minimum number of hex characters required by the number of allowable values. For example, if “square” is the eleventh out of fourteen allowable legProfile values, you could represent in your serialization with b as the twenty-fifth character (after the 24 for the floats). This is all highly dependent on the parametric object format, and great caution would be needed when dealing with any sort of versioning including so much as adding new allowable values for enumerated fields. However, if you truly need something minimal, this is the most straightforward approach I can think of.

No idea if this will be of any help at all, but hopefully it’s at least got some thoughts worth thinking about. :upside_down_face:


Thanks @syntheticmagus for your comprehensive reply! Yes it is helpful and is along the lines of what I was thinking.

I guess the other option is I could use a short UUID that refers (is a key) to both a parametric object’s state (stored in the database) and the corresponding cached static object file name. That might be a simpler approach, but I’ll do some testing to see what will work best.