Ionic storage, replace


#1

I am using IonicStorageModule to store a key value pair in my project, and let’s say the value is a json object named JSONSTORE.
My question is,

I am storing new sets of values in JSONSTORE and using storage.set() on the same key that i already used.

I know that it will replace all the other previous data stored in the storage module.
But is it necessary for me to call storage.remove(key) to maintain performance improvements, or should i simply call storage.set() again without removing anything?


#2

Use storage set. No problem


#3

No i mean, will it replace the data i stored with the same key or will it create a new instance of the storage with the same key but different value?


#4

hi @kevred

you can create a same key array and store multiple different values.

thanks


#5

actually, i am using a setinterval function that calles the storage.set() again and again after some 10 seconds. and it is calling the storage.set() on a same key and the value is changing, but i need only the newest value. My question is whether without calling storage.remove(), will affect my storage performance?

simply calling storage.set() with the same key i called previusly will it remove the old value and store the new set of values or will it create a new instance of the store with the same key but different values?

Will it gets bigger over time? i dont want that to happen

Thank you very much for your replies guys.


#6

It willnreplcae the value


#7

in this way you push data to an old variable and then store into localstore

this.allData.push({'new values'});

this.localstore.set('key name',this.allData);

#8

so no multiple storing of the key value pair right?
I dont’t want to use storage.remove() right?


#9

No it will not store the same key value pair multiple times. (Doesn’t make sense to do so neither)
.set() will create and/or replace the key value pair. No need to call .remove()


#10

writing to storage every 10secs may drain the battery though :slight_smile:

So curious about the use case for that!


#11

But i am getting a json object every 10 second from an api that i should use though.
Is there any other method other than storing the value to show it in my page?