Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(proxy-cache): the cache_zone field in the schema should be optional #2776

Merged
merged 3 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apisix/plugins/proxy-cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ local schema = {
properties = {
cache_zone = {
type = "string",
minLength = 1
minLength = 1,
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
default = "disk_cache_one",
},
cache_key = {
type = "array",
Expand Down Expand Up @@ -91,7 +92,6 @@ local schema = {
},
},
},
required = {"cache_zone"},
}

local _M = {
Expand Down
2 changes: 1 addition & 1 deletion doc/plugins/proxy-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The proxy-cache plugin, which provides the ability to cache upstream response da

| Name | Type | Requirement | Default | Valid | Description |
| ------------------ | -------------- | ----------- | ------------------------- | ------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cache_zone | string | required | | | Specify which cache area to use, each cache area can be configured with different paths. In addition, cache areas can be predefined in conf/config.yaml file |
| cache_zone | string | optional | disk_cache_one | | Specify which cache area to use, each cache area can be configured with different paths. In addition, cache areas can be predefined in conf/config.yaml file |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to tell people the cache will be invalid if cache_zone do not match.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this sounds great.

| cache_key | array[string] | optional | ["$host", "$request_uri"] | | key of a cache, can use variables. For example: ["$host", "$uri", "-cache-id"] |
| cache_bypass | array[string] | optional | | | Whether to skip cache retrieval. That is, do not look for data in the cache. It can use variables, and note that cache data retrieval will be skipped when the value of this attribute is not empty or not '0'. For example: ["$arg_bypass"] |
| cache_method | array[string] | optional | ["GET", "HEAD"] | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD","OPTIONS", "CONNECT", "TRACE"] | Decide whether to be cached according to the request method |
Expand Down
2 changes: 1 addition & 1 deletion doc/zh-cn/plugins/proxy-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| ------------------ | -------------- | ------ | ------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| cache_zone | string | 必须 | | | 指定使用哪个缓存区域,不同的缓存区域可以配置不同的路径,在conf/config.yaml文件中可以预定义使用的缓存区域 |
| cache_zone | string | 可选 | disk_cache_one | | 指定使用哪个缓存区域,不同的缓存区域可以配置不同的路径,在conf/config.yaml文件中可以预定义使用的缓存区域 |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more details about how to use this config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update later.

| cache_key | array[string] | 可选 | ["$host", "$request_uri"] | | 缓存key,可以使用变量。例如:["$host", "$uri", "-cache-id"] |
| cache_bypass | array[string] | 可选 | | | 是否跳过缓存检索,即不在缓存中查找数据,可以使用变量,需要注意当此参数的值不为空或非'0'时将会跳过缓存的检索。例如:["$arg_bypass"] |
| cache_method | array[string] | 可选 | ["GET", "HEAD"] | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD","OPTIONS", "CONNECT", "TRACE"] | 根据请求method决定是否需要缓存 |
Expand Down
34 changes: 30 additions & 4 deletions t/plugin/proxy-cache.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ run_tests;

__DATA__

=== TEST 1: sanity check (missing required field)
=== TEST 1: sanity check (missing cache_zone field, the default value is disk_cache_one)
--- config
location /t {
content_by_lua_block {
Expand All @@ -83,6 +83,32 @@ __DATA__
"type": "roundrobin"
},
"uri": "/hello"
}]],
[[{
"node": {
"value": {
"uri": "/hello",
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"plugins": {
"proxy-cache":{
"cache_zone":"disk_cache_one",
"hide_cache_headers":true,
"cache_bypass":["$arg_bypass"],
"cache_key":["$host","$request_uri"],
"no_cache":["$arg_no_cache"],
"cache_http_status":[200],
"cache_method":["GET"]
}
}
},
"key": "/apisix/routes/1"
},
"action": "set"
}]]
)

Expand All @@ -94,9 +120,9 @@ __DATA__
}
--- request
GET /t
--- error_code: 400
--- response_body eval
qr/failed to check the configuration of plugin proxy-cache/
--- error_code: 200
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
--- response_body
passed
--- no_error_log
[error]

Expand Down