shreemaan-abhishek commented on issue #9750:
URL: https://github.com/apache/apisix/issues/9750#issuecomment-1614414952

   > I reported this on Slack and they told me it wasn't an expected behaviour
   
   Hi, I think there has been a miscommunication, I said that the variable not 
being cleared at the end of the request is not expected behavior. Like the 
document says, the custom variable is indeed global.
   
   The problem is in your code:
   
   ```lua
   local function retrieve_info(conf,ctx,etcd,plugin_name)
     
       local cached_api_endpoint_info = ctx.var.cb_api_endpoint_info    -- [1]
       if cached_api_endpoint_info then
         return cached_api_endpoint_info -- [2]
       end 
   
       local key = ctx.var.uri   -- [3]
       
       core.ctx.register_var("cb_api_endpoint_info", function(ctx)
           return key
       end)
       
       return key
      
     end
   ```
   
   When you try to access the variable [1], it gets you the value from the 
previous request when it was set in [3]. On subsequent requests, the variable 
`key` is not updated because the cached value is returned in [2] ( [3] never 
gets executed again).
   
   
   If you add logs to the official code to see how many times the cache is hit 
and how many times you will see the feature working as expected.


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to