fix: use normal mutex for cache
This commit is contained in:
parent
1ebba7f2b7
commit
6d541cbfb9
|
@ -24,7 +24,7 @@ type SessionEntry struct {
|
||||||
// SessionStore struct to store the env variables
|
// SessionStore struct to store the env variables
|
||||||
type SessionStore struct {
|
type SessionStore struct {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
mutex sync.RWMutex
|
mutex sync.Mutex
|
||||||
store map[string]*SessionEntry
|
store map[string]*SessionEntry
|
||||||
// stores expireTime: key to remove data when cache is full
|
// stores expireTime: key to remove data when cache is full
|
||||||
// map is sorted by key so older most entry can be deleted first
|
// map is sorted by key so older most entry can be deleted first
|
||||||
|
@ -35,7 +35,7 @@ type SessionStore struct {
|
||||||
// NewSessionStore create a new session store
|
// NewSessionStore create a new session store
|
||||||
func NewSessionStore() *SessionStore {
|
func NewSessionStore() *SessionStore {
|
||||||
store := &SessionStore{
|
store := &SessionStore{
|
||||||
mutex: sync.RWMutex{},
|
mutex: sync.Mutex{},
|
||||||
store: make(map[string]*SessionEntry),
|
store: make(map[string]*SessionEntry),
|
||||||
keyIndex: make(map[int64]string),
|
keyIndex: make(map[int64]string),
|
||||||
stop: make(chan struct{}),
|
stop: make(chan struct{}),
|
||||||
|
@ -71,8 +71,8 @@ func (s *SessionStore) clean() {
|
||||||
|
|
||||||
// Get returns the value of the key in state store
|
// Get returns the value of the key in state store
|
||||||
func (s *SessionStore) Get(key, subKey string) string {
|
func (s *SessionStore) Get(key, subKey string) string {
|
||||||
s.mutex.RLock()
|
s.mutex.Lock()
|
||||||
defer s.mutex.RUnlock()
|
defer s.mutex.Unlock()
|
||||||
currentTime := time.Now().Unix()
|
currentTime := time.Now().Unix()
|
||||||
k := fmt.Sprintf("%s:%s", key, subKey)
|
k := fmt.Sprintf("%s:%s", key, subKey)
|
||||||
if v, ok := s.store[k]; ok {
|
if v, ok := s.store[k]; ok {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user