Skip to content

Commit 67b867d

Browse files
committed
doc(README): update README with latest changes
1 parent 5a3c4ad commit 67b867d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Easily write offline-first react-native applications with your own REST API. Thi
1818
- [Services options](#services-options)
1919
- [Fetch options](#fetch-options)
2020
- [Path and query parameters](#path-and-query-parameters)
21+
- [Limiting the size of your cache](#limiting-the-size-of-your-cache)
2122
- [Middlewares](#middlewares)
2223
- [Using your own driver for caching](#using-your-own-driver-for-caching)
2324
- [Types](#types)
@@ -153,6 +154,9 @@ Key | Type | Description | Example
153154
`printNetworkRequests` | `boolean` | Optional, prints all your network requests
154155
`disableCache` | `boolean` | Optional, completely disables caching (overriden by service definitions & `fetch`'s `option` parameter)
155156
`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)
156160
`offlineDriver` | `IAPIDriver` | Optional, see [use your own driver for caching](#use-your-own-driver-for-caching)
157161

158162
## Services options
@@ -168,6 +172,8 @@ Key | Type | Description | Example
168172
`prefix` | `string` | Optional specific prefix to use for this service, provide the key you set in your `prefixes` API option
169173
`middlewares` | `APIMiddleware[]` | Optional array of middlewares that override the ones set globally in your `middlewares` API option, , see [middlewares](#middlewares)
170174
`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)
171177

172178
## Fetch options
173179

@@ -194,6 +200,14 @@ The URL to your endpoints are being constructed with **your domain name, your op
194200

195201
* 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`.
196202

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+
197211
## Middlewares
198212

199213
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.
258272

259273
* `getItem(key: string, callback?: (error?: Error, result?: string) => void)`
260274
* `setItem(key: string, value: string, callback?: (error?: Error) => void);`
275+
* `removeItem(key: string, callback?: (error?: Error) => void);`
261276
* `multiRemove(keys: string[], callback?: (errors?: Error[]) => void);`
262277

263278
*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
273288
Pull requests are more than welcome for these items, or for any feature that might be missing.
274289

275290
- [ ] 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
276293
- [ ] Thoroughly test custom caching drivers, maybe provide one (realm or sqlite)
277294
- [ ] Add automated testing

0 commit comments

Comments
 (0)