You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/02/24 00:31:31 UTC

[GitHub] [incubator-apisix] membphis commented on a change in pull request #1153: feature: support for proxy caching plugin based on disk.

membphis commented on a change in pull request #1153: feature: support for proxy caching plugin based on disk.
URL: https://github.com/apache/incubator-apisix/pull/1153#discussion_r383055441
 
 

 ##########
 File path: lua/apisix/plugins/proxy-cache.lua
 ##########
 @@ -0,0 +1,247 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local core = require("apisix.core")
+local tab_insert = table.insert
+local tab_concat = table.concat
+local re_gmatch = ngx.re.gmatch
+local ngx = ngx
+local ipairs = ipairs
+local tostring = tostring
+
+local lrucache = core.lrucache.new({
+    ttl = 300, count = 100
+})
+
+local plugin_name = "proxy-cache"
+
+local schema = {
+    type = "object",
+    properties = {
+        cache_zone = {
+            type = "string",
+            minLength = 1
+        },
+        cache_key = {
+            type = "string",
+            minLength = 1
+        },
+        cache_http_status = {
+            type = "array",
+            minItems = 1,
+            items = {
+                description = "http response status",
+                type = "integer",
+                minimum = 200,
+                maximum = 599,
+            },
+            uniqueItems = true,
+            default = {200, 301, 404},
+        },
+        cache_method = {
+            type = "array",
+            minItems = 1,
+            items = {
+                description = "http method",
+                type = "string",
+                enum = {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD",
+                    "OPTIONS", "CONNECT", "TRACE"},
+                default = {"GET", "HEAD"},
+            },
+            uniqueItems = true,
+            default = {"GET", "HEAD"},
+        },
+        hide_cache_headers = {
+            type = "boolean",
+            default = false,
+        },
+        cache_strategy = {
+            type = "string",
+            default = "disk",
+            enum = {"disk", "memory"},
+            minLength = 0
+        },
+        cache_bypass = {
+            type = "string",
+            default = "1",
+            minLength = 0
+        },
+        no_cache = {
+            type = "string",
+            default = "0",
+            minLength = 0
+        },
+    },
+    required = {"cache_zone", "cache_key"},
+}
+
+local _M = {
+    version = 0.1,
+    priority = 1007,
+    name = plugin_name,
+    schema = schema,
+}
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    if conf.cache_strategy == "memory" then
+        return false, "memory cache is not yet supported."
+    end
+
+    local t = {}
+    for _, method in ipairs(conf.cache_method) do
 
 Review comment:
   That is not a good way for the dashboard. the dashboard submits `cache_method` in an array way, but it will get `cache_method` in a hash way.  
   
   It will make the dashboard developer confuse.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services