From f07b6436896abc64ae2d0d53746fef64852c7ebf Mon Sep 17 00:00:00 2001 From: martinsaporiti Date: Wed, 2 Oct 2024 09:26:36 -0300 Subject: [PATCH] fx: mutex --- internal/loader/w3c_loader.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/loader/w3c_loader.go b/internal/loader/w3c_loader.go index cb03b4d41..ac6a73e74 100644 --- a/internal/loader/w3c_loader.go +++ b/internal/loader/w3c_loader.go @@ -18,13 +18,13 @@ type W3CDocumentLoader struct { } type w3CDocumentLoaderLocalCache struct { - mutex sync.Mutex + mutex sync.RWMutex data map[string]*ld.RemoteDocument } func newLocalCache() *w3CDocumentLoaderLocalCache { return &w3CDocumentLoaderLocalCache{ - mutex: sync.Mutex{}, + mutex: sync.RWMutex{}, data: make(map[string]*ld.RemoteDocument), } } @@ -39,8 +39,8 @@ func (c *w3CDocumentLoaderLocalCache) Get(key string) (doc *ld.RemoteDocument, e func (c *w3CDocumentLoaderLocalCache) Set(key string, doc *ld.RemoteDocument, expireTime time.Time) error { c.mutex.Lock() + defer c.mutex.Unlock() c.data[key] = doc - c.mutex.Unlock() return nil }