diff --git a/docs/config/sidebar.md b/docs/config/sidebar.md index d2296e7..3e451e3 100644 --- a/docs/config/sidebar.md +++ b/docs/config/sidebar.md @@ -2,6 +2,7 @@ - [Introduction](pages/introduction.md 'Introduction') - [Installing](pages/installing.md 'Installing') + - [Usage & Examples](pages/usage-examples.md 'Interceptor') - [Storages](pages/storages.md 'Custom storages') - Cache Interceptor API diff --git a/docs/pages/per-request-configuration.md b/docs/pages/per-request-configuration.md index 0c3985f..0d1d1d2 100644 --- a/docs/pages/per-request-configuration.md +++ b/docs/pages/per-request-configuration.md @@ -39,9 +39,9 @@ determine their TTL value to override this If activated, when the response is received, the `ttl` property will be inferred from the requests headers. See the actual implementation of the -[`interpretHeader`](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/src/header/interpreter.ts) method for more information. You can -override the default behavior by setting the `headerInterpreter` when creating the cached -axios client. +[`interpretHeader`](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/src/header/interpreter.ts) +method for more information. You can override the default behavior by setting the +`headerInterpreter` when creating the cached axios client. ## `cache.methods` @@ -52,7 +52,9 @@ Defaults to only `GET` methods. ## `cache.cachePredicate` An object or function that will be tested against the response to test if it can be -cached. See the [inline documentation](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/src/util/cache-predicate.ts) for more. +cached. See the +[inline documentation](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/src/util/cache-predicate.ts) +for more. An simple example with all values: diff --git a/docs/pages/request-id.md b/docs/pages/request-id.md index 2c34c73..988a805 100644 --- a/docs/pages/request-id.md +++ b/docs/pages/request-id.md @@ -19,4 +19,6 @@ axios.get('...', { }); ``` -The [default](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/src/util/key-generator.ts) id generation can clarify this idea. +The +[default](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/src/util/key-generator.ts) +id generation can clarify this idea. diff --git a/docs/pages/storages.md b/docs/pages/storages.md index e6526ae..2381e61 100644 --- a/docs/pages/storages.md +++ b/docs/pages/storages.md @@ -3,8 +3,10 @@ A storage is the main object responsible for saving, retrieving and serializing (if needed) cache data. There are two simple ones that comes by default: -- [In Memory](https://github.com/arthurfiorette/axios-cache-interceptor/tree/main/src/storage/memory.ts) with `buildMemoryStorage` (Node and Web) -- [Web Storage API](https://github.com/arthurfiorette/axios-cache-interceptor/tree/main/src/storage/web-api.ts) with `buildWebStorage` (Web only) +- [In Memory](https://github.com/arthurfiorette/axios-cache-interceptor/tree/main/src/storage/memory.ts) + with `buildMemoryStorage` (Node and Web) +- [Web Storage API](https://github.com/arthurfiorette/axios-cache-interceptor/tree/main/src/storage/web-api.ts) + with `buildWebStorage` (Web only) Both of them are included in all bundles. diff --git a/docs/pages/usage-examples.md b/docs/pages/usage-examples.md new file mode 100644 index 0000000..2ad9e6c --- /dev/null +++ b/docs/pages/usage-examples.md @@ -0,0 +1,58 @@ +# Interceptor + +## Applying + +This library is based on axios interceptors, so, under the hood, it uses +`axios.interceptors.use()` to apply the interceptors. But you don't. All you have to do is +call `setupCache` and you are ready to go! + +```js +import { setupCache } from 'axios-cache-interceptor'; + +setupCache(axios); +``` + +### How to get the axios instance + +There are two types of axios instances, the `AxiosStatic` and the `AxiosInstance`. The +`AxiosStatic` is the default instance of axios. The `AxiosInstance` is the instance you +get when you call `axios.create()`. + +Both of them work seamlessly, but when messing with the axios static, your hole code, +_including those libraries you don't know that their exists_, are also affected. **You +should be careful when using it.** + +```js +// AxiosStatic +import axios from 'axios'; + +// AxiosInstance +const instance = axios.create(); +``` + +## Customizing behaviors + +You can customize the behaviors of this library in two ways, in a +[per request](pages/per-request-configuration.md) or in a +[global](pages/global-configuration.md) way. + +```js +import Axios from 'axios'; + +const instance = Axios.create({ + /** Here you can pass the axios options * */ +}); + +// Global +setupCache(instance, { + /** Here you can pass the interceptor options * */ +}); + +// Per request +await instance.get('url', { + /** Override axios options * */ + cache: { + /** Override cache options * */ + } +}); +```