diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
commit | 87d772a7d708fec12f48cd8adc0dedff6e1025da (patch) | |
tree | 1fee344c64cc3f43074a01981e21126c8482a522 /src/go/plugin/go.d/modules/proxysql/cache.go | |
parent | Adding upstream version 1.46.3. (diff) | |
download | netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.tar.xz netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.zip |
Adding upstream version 1.47.0.upstream/1.47.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/go/plugin/go.d/modules/proxysql/cache.go')
-rw-r--r-- | src/go/plugin/go.d/modules/proxysql/cache.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/go/plugin/go.d/modules/proxysql/cache.go b/src/go/plugin/go.d/modules/proxysql/cache.go new file mode 100644 index 000000000..c4fccefff --- /dev/null +++ b/src/go/plugin/go.d/modules/proxysql/cache.go @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package proxysql + +type ( + cache struct { + commands map[string]*commandCache + users map[string]*userCache + backends map[string]*backendCache + } + commandCache struct { + command string + hasCharts, updated bool + } + userCache struct { + user string + hasCharts, updated bool + } + backendCache struct { + hg, host, port string + hasCharts, updated bool + } +) + +func (c *cache) reset() { + for k, m := range c.commands { + c.commands[k] = &commandCache{command: m.command, hasCharts: m.hasCharts} + } + for k, m := range c.users { + c.users[k] = &userCache{user: m.user, hasCharts: m.hasCharts} + } + for k, m := range c.backends { + c.backends[k] = &backendCache{hg: m.hg, host: m.host, port: m.port, hasCharts: m.hasCharts} + } +} + +func (c *cache) getCommand(command string) *commandCache { + v, ok := c.commands[command] + if !ok { + v = &commandCache{command: command} + c.commands[command] = v + } + return v +} + +func (c *cache) getUser(user string) *userCache { + v, ok := c.users[user] + if !ok { + v = &userCache{user: user} + c.users[user] = v + } + return v +} + +func (c *cache) getBackend(hg, host, port string) *backendCache { + id := backendID(hg, host, port) + v, ok := c.backends[id] + if !ok { + v = &backendCache{hg: hg, host: host, port: port} + c.backends[id] = v + } + return v +} |