Skip to content

Commit eb2e5db

Browse files
authored
Merge pull request #22 from DianaIonita/feature/improve-readme
Improving readme
2 parents b1159f4 + 73567d9 commit eb2e5db

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

README.md

+60-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ You can configure how to handle unauthorized requests to invalidate a cache key
1818
* `IgnoreWithWarning` - ignores the request to invalidate and adds a `warning` header in the response.
1919
* `Fail` - fails the request to invalidate the cache key with a 403 response status code.
2020

21-
## Example
21+
## Examples
22+
23+
### Minimal setup
2224

2325
```yml
2426
plugins:
@@ -28,24 +30,71 @@ custom:
2830
# Enable or disable caching globally
2931
apiGatewayCaching:
3032
enabled: true
31-
clusterSize: '0.5' # defaults to '0.5'
32-
ttlInSeconds: 300 # defaults to the maximum allowed: 3600
33-
perKeyInvalidation:
34-
requireAuthorization: true # default is true
35-
handleUnauthorizedRequests: IgnoreWithWarning # default is "IgnoreWithWarning"
3633

3734
functions:
38-
# Responses are not cached
35+
# Responses are cached
3936
list-all-cats:
4037
handler: rest_api/cats/get/handler.handle
41-
role: listCatsRole
4238
events:
4339
- http:
4440
path: /cats
4541
method: get
4642
caching:
47-
enabled: false # default is false
43+
enabled: true
44+
45+
# Responses are *not* cached
46+
update-cat:
47+
handler: rest_api/cat/post/handler.handle
48+
events:
49+
- http:
50+
path: /cat
51+
method: post
52+
53+
# Responses are cached based on the 'pawId' path parameter and the 'Accept-Language' header
54+
get-cat-by-paw-id:
55+
handler: rest_api/cat/get/handler.handle
56+
events:
57+
- http:
58+
path: /cats/{pawId}
59+
method: get
60+
caching:
61+
enabled: true
62+
cacheKeyParameters:
63+
- name: request.path.pawId
64+
- name: request.header.Accept-Language
65+
```
66+
67+
### Configuring the cache cluster size and cache time to live
68+
Cache time to live and invalidation settings are applied to all functions, unless specifically overridden.
69+
70+
```yml
71+
plugins:
72+
- serverless-api-gateway-caching
4873

74+
custom:
75+
# Enable or disable caching globally
76+
apiGatewayCaching:
77+
enabled: true
78+
clusterSize: '0.5' # defaults to '0.5'
79+
ttlInSeconds: 300 # defaults to the maximum allowed: 3600
80+
perKeyInvalidation:
81+
requireAuthorization: true # default is true
82+
handleUnauthorizedRequests: Ignore # default is "IgnoreWithWarning"
83+
84+
```
85+
86+
### Configuring per-function cache time to live, cache invalidation strategy and cache key parameters
87+
88+
```yml
89+
plugins:
90+
- serverless-api-gateway-caching
91+
92+
custom:
93+
# Enable or disable caching globally
94+
apiGatewayCaching:
95+
enabled: true
96+
97+
functions:
4998
# Responses are cached based on the 'pawId' path parameter and the 'Accept-Language' header
5099
get-cat-by-paw-id:
51100
handler: rest_api/cat/get/handler.handle
@@ -57,8 +106,8 @@ functions:
57106
enabled: true
58107
ttlInSeconds: 3600
59108
perKeyInvalidation:
60-
requireAuthorization: true
61-
handleUnauthorizedRequests: Ignore
109+
requireAuthorization: true # default is true
110+
handleUnauthorizedRequests: Fail # default is "IgnoreWithWarning"
62111
cacheKeyParameters:
63112
- name: request.path.pawId
64113
- name: request.header.Accept-Language

0 commit comments

Comments
 (0)