Skip to content

Commit fe4ef1d

Browse files
author
Clément Le Provost
committed
[doc][offline] Update documentation
[ci skip]
1 parent 4ff1e95 commit fe4ef1d

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

doc/offline-mode.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ Offline features are brought by Algolia's **Offline SDK**, which is actually com
5959
client = OfflineClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
6060
```
6161

62-
4. (Optional) Choose the directory under which local indices will be stored:
62+
4. *(Optional)* Choose the directory under which local indices will be stored:
6363

6464
```swift
65-
client.rootDataDir = TODO
65+
client.rootDataDir = NSSearchPathForDirectoriesInDomains(.ApplicationSupportDirectory, .UserDomainMask, true).first! + "/my-indices"
6666
```
6767

68-
By default, TODO.
68+
By default, indices are stored under an `algolia` subdirectory of the `Application Support` directory.
6969

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:** 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.
71+
72+
**Note:** The directory chosen for index storage is automatically excluded from iCloud/iTunes backup.
7173

7274
5. **Enable offline mode**:
7375

@@ -80,16 +82,16 @@ Offline features are brought by Algolia's **Offline SDK**, which is actually com
8082

8183
### Activation
8284

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.
8486

85-
However, until you explicitly enable the offline mode by calling `enableOfflineMode()`, your offline client behaves like a regular online client. The same goes for indices: *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 for indices: *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.
8688

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.
8890

8991

9092
### Synchronization
9193

92-
You have entire control over *what* is synchronized and *when*.
94+
You have entire control over **what** is synchronized and **when**.
9395

9496
#### What
9597

@@ -99,11 +101,11 @@ A *data selection query* is essentially a combination of a browse `Query` and a
99101

100102
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.)
101103

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!
103105

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.
105107

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).
107109

108110

109111
#### When
@@ -118,9 +120,9 @@ Alternatively, you may call `MirroredIndex.sync()` to force a sync to happen now
118120

119121
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.
120122
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.
122124

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.
124126

125127

126128
### Querying
@@ -129,26 +131,24 @@ The reason you have to choose when to synchronize is that the decision depends o
129131

130132
You query a mirrored index using the same `search()` method as a purely online index. This will use the offline mirror as a fallback in case of failure of the online request.
131133

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:
135135

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 if the 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.
137137

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.
139139

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.
141141

142-
You can switch between those two modes by setting `MirroredIndex.preventiveOfflineSearch`.
142+
#### Data origin
143143

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.
145145

146146

147147
#### Direct query
148148

149149
You may directly target the offline mirror if you want:
150150

151-
- for search queries: `searchMirror()`
151+
- for search queries: `searchOffline()`
152152
- for browse queries: `browseMirror()` and `browseMirrorFrom()`
153153

154154
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
170170
To do so:
171171

172172
- 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;
174174
- pre-fetch those that are not already available locally.
175175

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.
177177
178178
179179
@@ -207,7 +207,7 @@ Any unexpected condition should result in a warning/error being logged.
207207
208208
If you think you found a bug in the offline client, please submit an issue on GitHub so that it can benefit the community.
209209
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.
211211
212212
213213
## Other resources

0 commit comments

Comments
 (0)