in internal/plugin/conf.go [69:125]
func (cc *ConfCache) Set(req *pc.Req) (uint32, error) {
cc.lock.Lock()
defer cc.lock.Unlock()
key := string(req.Key())
// APISIX < 2.9 doesn't send the idempotent key
if key != "" {
res, err := cc.keyCache.Get(key)
if err == nil {
return res.(uint32), nil
}
if err != ttlcache.ErrNotFound {
log.Errorf("failed to get cached token with key: %s", err)
// recreate the token
}
}
entries := RuleConf{}
te := A6.TextEntry{}
for i := 0; i < req.ConfLength(); i++ {
if req.Conf(&te, i) {
name := string(te.Name())
plugin := findPlugin(name)
if plugin == nil {
log.Warnf("can't find plugin %s, skip", name)
continue
}
log.Infof("prepare conf for plugin %s", name)
v := te.Value()
conf, err := plugin.ParseConf(v)
if err != nil {
log.Errorf(
"failed to parse configuration for plugin %s, configuration: %s, err: %v",
name, string(v), err)
continue
}
entries = append(entries, ConfEntry{
Name: name,
Value: conf,
})
}
}
cc.tokenCounter++
token := cc.tokenCounter
err := cc.tokenCache.Set(strconv.FormatInt(int64(token), 10), entries)
if err != nil {
return 0, err
}
err = cc.keyCache.Set(key, token)
return token, err
}