You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, indices are stored under an `algolia` subdirectory of the `Application Support` directory.
69
69
70
-
*Warning: although using the cache directory may be tempting, we advise you against doing so. There is no guarantee that all files will be deleted together, and a partial delete could leave an index in an inconsistent state.*
70
+
**Warning:**Althoughusing the cache directory may be tempting, we advise you against doing so. There is no guarantee that all files will be deleted together, and a partial delete could leave an index in an inconsistent state.
71
+
72
+
**Note:**The directory chosen for index storage is automatically excluded from iCloud/iTunes backup.
71
73
72
74
5. **Enable offline mode**:
73
75
@@ -80,16 +82,16 @@ Offline features are brought by Algolia's **Offline SDK**, which is actually com
80
82
81
83
### Activation
82
84
83
-
An`OfflineClient` provides all the features of an online `Client`. It returns `MirroredIndex` instances, which in turn provide all the features of online `Index` instances.
85
+
An`OfflineClient` provides all the features of an online `Client`. It returns `MirroredIndex` instances, which also provide all the features of online `Index` instances.
84
86
85
-
However, until you explicitly enable the offline mode by calling `enableOfflineMode()`, your offline client behaves like a regular online client. The same goes forindices:*you must explicitly activate mirroring* by settings the `mirrored` property to `true`. The reason is that you might not want to mirror all of your indices.
87
+
However, until you explicitly enable the offline mode by calling `enableOfflineMode()`, your offline client behaves like a regular online client. The same goes forindices:*you must explicitly activate mirroring* by setting the `mirrored` property to `true`. The reason is that you might not want to mirror all of your indices.
86
88
87
-
*Warning:Calling offline features before enabling mirroring on an index is a programming error and will be punished by an assertion failure.*
89
+
**Warning:**Calling offline features before enabling mirroring on an index is a programming error and will be punished by an assertion failure.
88
90
89
91
90
92
### Synchronization
91
93
92
-
You have entire control over *what* is synchronized and*when*.
94
+
You have entire control over **what** is synchronized and**when**.
93
95
94
96
#### What
95
97
@@ -99,11 +101,11 @@ A *data selection query* is essentially a combination of a browse `Query` and a
99
101
100
102
It will do so for every data selection query you have provided, then build (or re-build) the local index from the retrieved data. (When re-building, the previous version of the local index remains available for querying, until it is replaced by the new version.)
101
103
102
-
*Warning:The entire selected data is re-downloaded at every sync, so be careful about bandwidth usage!*
104
+
**Warning:**The entire selected data is re-downloaded at every sync, so be careful about bandwidth usage!
103
105
104
-
*Warning:It is a programming error to attempt a sync with no data selection queries. Doing so will result in an assertion failure.*
106
+
**Warning:**It is a programming error to attempt a sync with no data selection queries. Doing so will result in an assertion failure.
105
107
106
-
*Note:Because the sync uses a "browse" to retrieve objects, the number of objects actually mirrored may exceed the maximum object count specified in the data selection query (up to one page of results of difference).*
108
+
**Note:**Because the sync uses a "browse" to retrieve objects, the number of objects actually mirrored may exceed the maximum object count specified in the data selection query (up to one page of results of difference).
107
109
108
110
109
111
#### When
@@ -118,9 +120,9 @@ Alternatively, you may call `MirroredIndex.sync()` to force a sync to happen now
118
120
119
121
The reason you have to choose when to synchronize is that the decision depends on various factors that the SDK cannot know, in particular the specific business rules of your application, or the user's preferences. For example, you may want to sync only when connected to a non-metered Wi-Fi network, or during the night.
120
122
121
-
*Note: Syncs always happen in the background, and therefore should not impact the user's experience.*
123
+
**Note:** Syncs always happen in the background, and therefore should not impact the user's experience.
122
124
123
-
*Note:You cannot have two syncs on the same index running in parallel. If a sync is already running, concurrent sync requests will be ignored.*
125
+
**Note:**You cannot have two syncs on the same index running in parallel. If a sync is already running, concurrent sync requests will be ignored.
124
126
125
127
126
128
### Querying
@@ -129,26 +131,24 @@ The reason you have to choose when to synchronize is that the decision depends o
129
131
130
132
You query a mirrored index using the same `search()` method as a purely online index. This will use the offline mirror as a fallback incase of failure of the online request.
131
133
132
-
There's a catch, however. A mirrored index can function in two modes:
133
-
134
-
1. **Preventive offline search** (default). In this mode, if the online request is too slow to return, an offline request is launched preventively after a certain delay.
134
+
You can customize this behavior by changing the `requestStrategy` property of the index:
135
135
136
-
*Warning: This may lead to your completion handler being called twice:* a first time with the offline results, and a second time with the online results. However, if the online request is fast enough (and successful, or the error cannot be recovered), the callback will be called just once.
136
+
-`FallbackOnFailure` (default) only falls back to the offline mirror ifthe online request fails. This covers cases where the device is offline; however, when the device is online but with a bad connectivity, every timeout has to be hit before the request is considered a failure.
137
137
138
-
You may adjust the delay setting the `MirroredIndex.preventiveOfflineSearchDelay` property. The default is `MirroredIndex.DefaultPreventiveOfflineSearchDelay`.
138
+
-To enforce a maximum response time, you can use `FallbackOnTimeout`, adjusting the timeout threshold via the `offlineFallbackTimeout` property.
139
139
140
-
2. **Offline fallback.** In this mode, the index first tries an online request, and in case of failure, switches back to the offline mirror, but only after the online request has failed. Therefore, the completion handler is guaranteed to be called exactly once.
140
+
-`OnlineOnly`and`OfflineOnly` are rather straightforward strategies, meant to implement custom strategies on top of them.
141
141
142
-
You can switch between those two modes by setting `MirroredIndex.preventiveOfflineSearch`.
142
+
#### Data origin
143
143
144
-
The origin of the data is indicated by the `origin` attribute in the returned result object: its value is `remote` if the content originates from the online API, and `local` if the content originates from the offline mirror.
144
+
The origin of the data is indicated by the `origin` attribute in the returned result object: its value is `remote`if the content originates from the online API, and`local`if the content originates from the offline mirror.When you are using a mixed online/offline request strategy (the default, see above), this lets you know where the response is coming from.
145
145
146
146
147
147
#### Direct query
148
148
149
149
You may directly target the offline mirror if you want:
Those methods have the same semantics as their online counterpart.
@@ -170,10 +170,10 @@ In order to offer the best user experience, you may want to pre-load some of tho
170
170
Todoso:
171
171
172
172
- register a listener on the mirrored index (see [Events](#events) above);
173
-
- when the sync is finished, browse the local mirror, parsing each object to detect associated resources;
173
+
-when the sync is finished, browse the local mirror (using`browseMirror()`and`browseMirrorFrom()`, see above), parsing each object to detect associated resources;
174
174
- pre-fetch those that are not already available locally.
175
175
176
-
*Note: You should do so from a background thread with a low priority to minimize impact on the user's experience.*
176
+
**Note:**You should do so from a background thread with a low priority to minimize impact on the user's experience.
177
177
178
178
179
179
@@ -207,7 +207,7 @@ Any unexpected condition should result in a warning/error being logged.
207
207
208
208
If you think you found a bug in the offline client, please submit an issue on GitHub so that it can benefit the community.
209
209
210
-
If you have a crash in the offline core, please send us a support request. Make sure to include the *crash report*, so that we can pinpoint the problem.
210
+
If you have a crash in the offline core, please send us a support request. Make sure to include the **crash report**, so that we can pinpoint the problem.
0 commit comments