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
Since this plugin is a fully-fledged wrapper and not just a network helper, you need to set up your API configuration.
@@ -153,6 +160,9 @@ Key | Type | Description | Example
153
160
`printNetworkRequests` | `boolean` | Optional, prints all your network requests
154
161
`disableCache` | `boolean` | Optional, completely disables caching (overriden by service definitions & `fetch`'s `option` parameter)
155
162
`cacheExpiration` | `number` | Optional default expiration of cached data in ms (overriden by service definitions & `fetch`'s `option` parameter)
163
+
`cachePrefix` | `string` | Optional, prefix of the keys stored on your cache, defaults to `offlineApiCache`
164
+
`capServices` | `boolean` | Optional, enable capping for every service, defaults to `false`, see [limiting the size of your cache](#limiting-the-size-of-your-cache)
165
+
`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
166
`offlineDriver` | `IAPIDriver` | Optional, see [use your own driver for caching](#use-your-own-driver-for-caching)
157
167
158
168
## Services options
@@ -168,6 +178,8 @@ Key | Type | Description | Example
168
178
`prefix` | `string` | Optional specific prefix to use for this service, provide the key you set in your `prefixes` API option
169
179
`middlewares` | `APIMiddleware[]` | Optional array of middlewares that override the ones set globally in your `middlewares` API option, , see [middlewares](#middlewares)
170
180
`disableCache` | `boolean` | Optional, disables the cache for this service (override your [API's global options](#api-options))
181
+
`capService` | `boolean` | Optional, enable or disable capping for this specific service, see [limiting the size of your cache](#limiting-the-size-of-your-cache)
182
+
`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
183
172
184
## Fetch options
173
185
@@ -194,11 +206,19 @@ The URL to your endpoints are being constructed with **your domain name, your op
194
206
195
207
* 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
208
209
+
## Limiting the size of your cache
210
+
211
+
If you fear your cache will keep growing, you have some options to make sure it doesn't get too big.
212
+
213
+
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.
214
+
215
+
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.
216
+
197
217
## Middlewares
198
218
199
219
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.**
200
220
201
-
You must provide an **array of promises**, like so : `(serviceDefinition: IAPIService, options: IFetchOptions) => any;`, please [take a look at the types](#types) to know more. You don't necessarily need to write asynchronous code in them, but they all must be promises.
221
+
You must provide an **array of promises**, like so : `(serviceDefinition: IAPIService, fullPath: string, options: IFetchOptions) => any;`, please [take a look at the types](#types) to know more. You don't necessarily need to write asynchronous code in them, but they all must be promises.
202
222
203
223
Anything you will resolve in those promises will be merged into your request's options !
204
224
@@ -258,6 +278,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 +294,7 @@ These are Typescript defintions, so they should be displayed in your editor/IDE
273
294
Pull requests are more than welcome for these items, or for any feature that might be missing.
274
295
275
296
-[ ] Write a demo
297
+
-[ ] 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
298
+
-[ ] 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
299
-[ ] Thoroughly test custom caching drivers, maybe provide one (realm or sqlite)
0 commit comments