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/28 13:51:28 UTC

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

agile6v 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_r385705627
 
 

 ##########
 File path: lua/apisix/plugins/proxy-cache.lua
 ##########
 @@ -0,0 +1,238 @@
+--
+-- 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 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 = 1009,
+    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
+
+    return true
+end
+
+-- Copy from redirect plugin, this function is useful.
+-- It can be extracted as a public function.
+local function parse_complex_value(complex_value)
+
+    local reg = [[ (\\\$[0-9a-zA-Z_]+) | ]]     -- \$host
+            .. [[ \$\{([0-9a-zA-Z_]+)\} | ]]    -- ${host}
+            .. [[ \$([0-9a-zA-Z_]+) | ]]        -- $host
+            .. [[ (\$|[^$\\]+) ]]               -- $ or others
+    local iterator, err = re_gmatch(complex_value, reg, "jiox")
+    if not iterator then
+        return nil, err
+    end
+
+    local t = {}
+    while true do
+        local m, err = iterator()
+        if err then
+            return nil, err
+        end
+
+        if not m then
+            break
+        end
+
+        tab_insert(t, m)
+    end
+
+    return t
+end
+
+
+local tmp = {}
+local function generate_complex_value(data, ctx)
 
 Review comment:
   It can parse strings like `${uri}/helloworld` 

----------------------------------------------------------------
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