ManagementSystem/modules/cache/cache.go

63 lines
1.3 KiB
Go

package cache
import (
"sync"
"clickandjoin.app/managementsystem/modules/structs"
"clickandjoin.app/managementsystem/modules/utils"
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
)
var socketClients = make(map[string]*structs.SocketClient)
var muS sync.RWMutex
func AddSocketClient(clientId string, socketClient *structs.SocketClient) {
muS.Lock()
socketClients[clientId] = socketClient
muS.Unlock()
}
func DeleteClient(clientId string) {
muS.Lock()
delete(socketClients, clientId)
muS.Unlock()
}
func GetSocketClients() map[string]*structs.SocketClient {
muS.RLock()
defer muS.RUnlock()
return socketClients
}
func GetSocketClient(clientId string) (socketClient *structs.SocketClient, ok bool) {
muS.RLock()
defer muS.RUnlock()
client, ok := socketClients[clientId]
return client, ok
}
var lastLogMessages []gocnjhelper.RabbitMqLogMessage
var muL sync.RWMutex
func AddLastLogMessages(rabbitMqLogMessage []gocnjhelper.RabbitMqLogMessage) {
muL.Lock()
if len(lastLogMessages) > utils.CachedLastLogMessages {
lastLogMessages = lastLogMessages[1:]
}
lastLogMessages = append(lastLogMessages, rabbitMqLogMessage...)
muL.Unlock()
}
func GetlastLogMessages() []gocnjhelper.RabbitMqLogMessage {
muL.RLock()
defer muL.RUnlock()
return lastLogMessages
}