| 89 | } |
| 90 | |
| 91 | push(item: QueryStoreItem) { |
| 92 | const items = [...this.items, item]; |
| 93 | |
| 94 | if (this.maxSize && items.length > this.maxSize) { |
| 95 | items.shift(); |
| 96 | } |
| 97 | |
| 98 | for (let attempts = 0; attempts < 5; attempts++) { |
| 99 | const response = this.storage.set( |
| 100 | this.key, |
| 101 | JSON.stringify({ [this.key]: items }), |
| 102 | ); |
| 103 | if (!response?.error) { |
| 104 | this.items = items; |
| 105 | } else if (response.isQuotaError && this.maxSize) { |
| 106 | // Only try to delete last items on LRU stores |
| 107 | items.shift(); |
| 108 | } else { |
| 109 | return; // We don't know what happened in this case, so just bailing out |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | save() { |
| 115 | this.storage.set(this.key, JSON.stringify({ [this.key]: this.items })); |