Correct usage of Ionic storage (best practise)

Hey guys,

there is no detail into how the Ionic Storage operates.

Hence I struggle with the most efficient usage.

I am using a provider to operate on my Ionic storage collections. I have a json object with a list of movie items. I store it in a collection as a JSON, i.e. myMovieStorage.set[‘myMovieCollection’, someMovieObject.json]

Now I have a filter for categories. The user can change the filter settings via a filter menu and store the settings. The movies would then be filtered based on the category collection

How should I store and operate with the selected categories? There are two approaches:

Store the whole category as JSON in one single collection such as:
storage.set[‘mySelectedCategories’, {‘Action’ : 1, ‘Comedy’: 0, 'Thriller:: 1, etc…}]
Then I would iterate through the JSON object to filter my movieCollection

Create a seperate storage provider to store the selection as key/value pairs, such as:
storage.set[‘Action’, 1]
storage.set[‘Thriller’, 0]
storage.set[‘Comedy’, 1]

How is the storage ment to be used in my case, what is more efficient in the end?

Thanks in advance!

It’s a hard question to answer, because Ionic Storage isn’t one thing. It’s a strategy that polls the device for available storage services and then chooses one. It has a default behavior (which choices to prioritize) that you can change if you want.

So the nuts and bolts of the storage operations might be very different from user A to user B.

Some general points: marshaling to and from JSON is expensive, and should be avoided as a general rule. Hence, key/value pairs and object are better. Also, not all data types are serializable (JSON-able), which is another vote for key/value pairs and objects. On the other hand, JSON is very easy to manipulate, bugs in logic are much easier to spot, and the extra time and overhead required for JSON isn’t that much. So is it worth an extra half a second to force yourself to write code that will be more difficult to create and harder to debug?

I think you should do some reading, and see how well different strategies match the problems you are trying to solve.