Storage, performance: get values from keys that begin with the same characters


#1

I’m looking at https://ionicframework.com/docs/storage/ and i’m questioning myself on the possibilty to store keys that begin always with the same characters (e.g “tan1 tan2 tan4”) and get the values from them.
I know that it’s possible but, the important part, can i get the values from these keys without loop all the keys in the storage using the forEach(iteratorCallback)?
Exist a way to get from the storage only the keys that begin in a particular way (e.g. “tan”) without check each key in the storage if it contains at the beginning the specific format? It could be a big problem on performance.

Thanks in advice.


#2

Depends on your expected data layout. It would be theoretically possible to chunk all the “tanX” entries into a single “tan” entry from the POV of storage. Whether that would be an improvement over looping across the whole set of keys I can’t say. Note that you don’t have to forEach across all values; you could call keys() and then fetch only those entries whose keys start with “tan”.


#3

You could also maintain your own “index” of keys in storage in a special key and make this one so that it helps you find the correct ones.