github.com/netdata/go.d.plugin@v0.58.1/modules/proxysql/cache.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package proxysql 4 5 type ( 6 cache struct { 7 commands map[string]*commandCache 8 users map[string]*userCache 9 backends map[string]*backendCache 10 } 11 commandCache struct { 12 command string 13 hasCharts, updated bool 14 } 15 userCache struct { 16 user string 17 hasCharts, updated bool 18 } 19 backendCache struct { 20 hg, host, port string 21 hasCharts, updated bool 22 } 23 ) 24 25 func (c *cache) reset() { 26 for k, m := range c.commands { 27 c.commands[k] = &commandCache{command: m.command, hasCharts: m.hasCharts} 28 } 29 for k, m := range c.users { 30 c.users[k] = &userCache{user: m.user, hasCharts: m.hasCharts} 31 } 32 for k, m := range c.backends { 33 c.backends[k] = &backendCache{hg: m.hg, host: m.host, port: m.port, hasCharts: m.hasCharts} 34 } 35 } 36 37 func (c *cache) getCommand(command string) *commandCache { 38 v, ok := c.commands[command] 39 if !ok { 40 v = &commandCache{command: command} 41 c.commands[command] = v 42 } 43 return v 44 } 45 46 func (c *cache) getUser(user string) *userCache { 47 v, ok := c.users[user] 48 if !ok { 49 v = &userCache{user: user} 50 c.users[user] = v 51 } 52 return v 53 } 54 55 func (c *cache) getBackend(hg, host, port string) *backendCache { 56 id := backendID(hg, host, port) 57 v, ok := c.backends[id] 58 if !ok { 59 v = &backendCache{hg: hg, host: host, port: port} 60 c.backends[id] = v 61 } 62 return v 63 }