Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 7fdb054

Browse files
committed
Added test for environement, better documentation
1 parent 7501beb commit 7fdb054

File tree

5 files changed

+2168
-1278
lines changed

5 files changed

+2168
-1278
lines changed

README.md

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,42 @@ Add the different hooks. The order matters (see below). A `cache` object will be
6060
If the cache object is not needed/wanted it can be removed with the after hook `hookRemoveCacheInformation()`
6161

6262
### Configuration
63+
#### Redis
64+
To configure the redis connection the feathers configuration system can be used.
65+
```js
66+
//config/default.json
67+
{
68+
"host": "localhost",
69+
"port": 3030,
70+
"redis": {
71+
"host": "my-redis-service.example.com",
72+
"port": 1234
73+
}
74+
}
75+
```
76+
* if no config is provided, default config from the [redis module](https://github.com/NodeRedis/node_redis) is used
6377

64-
A cache object can be added to the default feathers configuration
78+
#### Hooks Configuration
79+
A redisCache object can be added to the default feathers configuration
6580

6681
```js
6782
//config/default.json
6883

6984
"redisCache" : {
7085
"defaultDuration": 3600,
7186
"parseNestedRoutes": true,
72-
"removePathFromCacheKey": true
87+
"removePathFromCacheKey": true,
88+
"env": "NODE_ENV"
7389
};
7490
```
91+
##### defaultDuration
7592
The default duration can be configured by passing the duration in seconds to the property `defaultDuration`.
93+
This can be overridden at the hook level (see the full example bellow)
94+
95+
##### parseNestedRoutes
7696
If your API uses nested routes like `/author/:authorId/book` you should turn on the option `parseNestedRoutes`. Otherwise you could have conflicting cache keys.
97+
98+
##### removePathFromCacheKey
7799
`removePathFromCacheKey` is an option that is useful when working with content and slugs. If when this option is turned on you can have the following issue. If your routes use IDs then you could have a conflict and the cache might return the wrong value:
78100

79101
```js
@@ -83,10 +105,15 @@ If your API uses nested routes like `/author/:authorId/book` you should turn on
83105

84106
both items with id `123` would be saved under the same cache key... thus replacing each other and returning one for the other, thus by default the key includes the path to diferenciate them. when working with content you could have an external system busting the cache that is not aware of your API routes. That system would know the slug, but cannot bust the cache as it would have to call `/cache/clear/single/:path/target`, with this option that system can simply call `:target` which would be the slug/alias of the article.
85107

108+
##### env
109+
The default environement is production, but it is anoying when running test as the hooks output information to the console. Therefore if you youse this option, you can set `test` as an environement and the hooks will not output anything to the console. if you use `NODE_ENV` it will pick up the `process.env.NODE_ENV` variable. This is useful for CI or CLI.
110+
86111

87112
Available routes:
88113
```js
89-
'/cache/index' // returns an array with all the keys
114+
// this route is disable as I noticed issues when redis has many keys,
115+
// I will put it back when I have a more robust solution
116+
// '/cache/index' // returns an array with all the keys
90117
'/cache/clear' // clears the whole cache
91118
'/cache/clear/single/:target' // clears a single route if you want to purge a route with params just adds them target?param=1
92119
'/cache/clear/group/:target' // clears a group
@@ -168,24 +195,9 @@ module.exports = {
168195
* the duration is in seconds and will automatically expire
169196
* you may just use `cache()` without specifying a duration, any request will be cached for a day or with the global configured value (see configuration above).
170197

171-
172-
To configure the redis connection the feathers configuration system can be used.
173-
```js
174-
//config/default.json
175-
{
176-
"host": "localhost",
177-
"port": 3030,
178-
"redis": {
179-
"host": "my-redis-service.example.com",
180-
"port": 1234
181-
}
182-
}
183-
```
184-
* if no config is provided, default config from the [redis module](https://github.com/NodeRedis/node_redis) is used
185-
186198
## License
187199

188-
Copyright (c) 2017
200+
Copyright (c) 2018
189201

190202
Licensed under the [MIT license](LICENSE).
191203

0 commit comments

Comments
 (0)