HelloBug0 commented on issue #3112:
URL: https://github.com/apache/apisix/issues/3112#issuecomment-751319250


   I see. There is need to protect the cache when setting a stale object. In 
this way, I also have two questions.
   + Why do we lock the function execution of fetch_valid_cache in line 119? Is 
it OK if we call the function out of the lock?
   + I still don't clear that why we call the function of fetch_valid_cache 
twice. It‘s natually to think that the code from line 100 to line 134 to be 
programed like this.
   ```lua
           local cache_obj = fetch_valid_cache(lru_obj, invalid_stale, item_ttl,
                               item_release, key, version)
           if cache_obj then
               return cache_obj.val
           end
   
           local lock, err = resty_lock:new(lock_shdict_name)
           if not lock then
               return nil, "failed to create lock: " .. err
           end
   
           local key_s = tostring(key)
           log.info("try to lock with key ", key_s)
   
           local elapsed, err = lock:lock(key_s)
           if not elapsed then
               return nil, "failed to acquire the lock: " .. err
           end
   
           local obj, err = create_obj_fun(...)
           if obj ~= nil then
               lru_obj:set(key, {val = obj, ver = version}, item_ttl)
           end
           lock:unlock()
           log.info("unlock with key ", key_s)
   
           return obj, err
   ```


----------------------------------------------------------------
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:
[email protected]


Reply via email to