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
{{ message }}
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+31-19Lines changed: 31 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,20 +60,42 @@ Add the different hooks. The order matters (see below). A `cache` object will be
60
60
If the cache object is not needed/wanted it can be removed with the after hook `hookRemoveCacheInformation()`
61
61
62
62
### 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
63
77
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
65
80
66
81
```js
67
82
//config/default.json
68
83
69
84
"redisCache": {
70
85
"defaultDuration":3600,
71
86
"parseNestedRoutes":true,
72
-
"removePathFromCacheKey":true
87
+
"removePathFromCacheKey":true,
88
+
"env":"NODE_ENV"
73
89
};
74
90
```
91
+
##### defaultDuration
75
92
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
76
96
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
77
99
`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:
78
100
79
101
```js
@@ -83,10 +105,15 @@ If your API uses nested routes like `/author/:authorId/book` you should turn on
83
105
84
106
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.
85
107
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
+
86
111
87
112
Available routes:
88
113
```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
90
117
'/cache/clear'// clears the whole cache
91
118
'/cache/clear/single/:target'// clears a single route if you want to purge a route with params just adds them target?param=1
92
119
'/cache/clear/group/:target'// clears a group
@@ -168,24 +195,9 @@ module.exports = {
168
195
* the duration is in seconds and will automatically expire
169
196
* 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).
170
197
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
0 commit comments