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
Copy file name to clipboardExpand all lines: README.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ Easily write offline-first react-native applications with your own REST API. Thi
18
18
-[Services options](#services-options)
19
19
-[Fetch options](#fetch-options)
20
20
-[Path and query parameters](#path-and-query-parameters)
21
+
-[Limiting the size of your cache](#limiting-the-size-of-your-cache)
21
22
-[Middlewares](#middlewares)
22
23
-[Using your own driver for caching](#using-your-own-driver-for-caching)
23
24
-[Types](#types)
@@ -153,6 +154,9 @@ Key | Type | Description | Example
153
154
`printNetworkRequests` | `boolean` | Optional, prints all your network requests
154
155
`disableCache` | `boolean` | Optional, completely disables caching (overriden by service definitions & `fetch`'s `option` parameter)
155
156
`cacheExpiration` | `number` | Optional default expiration of cached data in ms (overriden by service definitions & `fetch`'s `option` parameter)
157
+
`cachePrefix` | `string` | Optional, prefix of the keys stored on your cache, defaults to `offlineApiCache`
158
+
`capServices` | `boolean` | Optional, enable capping for every service, defaults to `false`, see [limiting the size of your cache](#limiting-the-size-of-your-cache)
159
+
`capLimit` | `number` | Optional quantity of cached items for each service, defaults to `50`, see [limiting the size of your cache](#limiting-the-size-of-your-cache)
156
160
`offlineDriver` | `IAPIDriver` | Optional, see [use your own driver for caching](#use-your-own-driver-for-caching)
157
161
158
162
## Services options
@@ -168,6 +172,8 @@ Key | Type | Description | Example
168
172
`prefix` | `string` | Optional specific prefix to use for this service, provide the key you set in your `prefixes` API option
169
173
`middlewares` | `APIMiddleware[]` | Optional array of middlewares that override the ones set globally in your `middlewares` API option, , see [middlewares](#middlewares)
170
174
`disableCache` | `boolean` | Optional, disables the cache for this service (override your [API's global options](#api-options))
175
+
`capService` | `boolean` | Optional, enable or disable capping for this specific service, see [limiting the size of your cache](#limiting-the-size-of-your-cache)
176
+
`capLimit` | `number` | Optional quantity of cached items for this specific service, defaults to `50`, see [limiting the size of your cache](#limiting-the-size-of-your-cache)
171
177
172
178
## Fetch options
173
179
@@ -194,6 +200,14 @@ The URL to your endpoints are being constructed with **your domain name, your op
194
200
195
201
* The `queryParameters` are regular query string parameters. For instance, a request fired with this path : `/weather` and these `queryParameters` : `{ days: 'mon,tue,sun', location: 'Paris,France' }` will become `/weather?days=mon,tue,sun&location=Paris,France`.
196
202
203
+
## Limiting the size of your cache
204
+
205
+
If you fear your cache will keep growing, you have some options to make sure it doesn't get too big.
206
+
207
+
First, you can use the `clearCache` method to empty all stored data, or just a service's items. You might want to implement a button in your interface to give your users the ability to clear it whenever they want if they feel like their app is starting to take too much space.
208
+
209
+
The other solution would be to use the capping option. If you set `capServices` to true in your [API options](#api-options), or `capService` in your [service options](#services-options), the wrapper will make sure it never stores more items that the amount you configured in `capLimit`. This is a good way to restrict the size of stored data for sensitive services, while leaving some of them uncapped. Capping is disabled by default.
210
+
197
211
## Middlewares
198
212
199
213
Just like for the other request options, **you can provide middlewares at the global level in your API options, at the service's definition level, or in the `options` parameter of the `fetch` method.**
@@ -258,6 +272,7 @@ Your custom driver must implement these 3 methods that are promises.
*Please note that, as of the 1.0 release, this hasn't been tested thoroughly.*
@@ -273,5 +288,7 @@ These are Typescript defintions, so they should be displayed in your editor/IDE
273
288
Pull requests are more than welcome for these items, or for any feature that might be missing.
274
289
275
290
-[ ] Write a demo
291
+
-[ ] Improve capping performance by storing how many items are cached for each service so we don't have to parse the whole service's dictionary each time
292
+
-[ ] Add a method to check for the total size of the cache, which would be useful to trigger a clearing if it reaches a certain size
276
293
-[ ] Thoroughly test custom caching drivers, maybe provide one (realm or sqlite)
0 commit comments