Skip to content

Commit 10e09b6

Browse files
authored
Merge pull request #2 from cgauge/map-issue
Use RWMutex for better concurrency
2 parents dc7e86f + 6e04446 commit 10e09b6

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.17-alpine as build
1+
FROM golang:1.23-alpine AS build
22

33
ARG CGO_ENABLED=0
44

@@ -12,14 +12,14 @@ RUN go mod download
1212

1313
COPY . .
1414

15-
FROM build as build-sidecar
15+
FROM build AS build-sidecar
1616

1717
ARG CGO_ENABLED=0
1818

1919
RUN go build -ldflags="-s -w" -o /cache-server main_container.go \
2020
&& upx --best --lzma /cache-server
2121

22-
FROM build as build-extension
22+
FROM build AS build-extension
2323

2424
ARG CGO_ENABLED=0
2525

secrets/cache.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type CacheData struct {
2727
CacheExpiry time.Time
2828
}
2929

30-
var mutex = &sync.Mutex{}
30+
var mutex = &sync.RWMutex{}
3131

3232
func IsExpired(cacheExpiry time.Time) bool {
3333
return cacheExpiry.Before(time.Now())
@@ -48,9 +48,14 @@ func GetCacheExpiry() time.Time {
4848
}
4949

5050
func GetSecretCache(name string, refresh string) string {
51+
mutex.RLock()
5152
secret := secretCache[name]
53+
mutex.RUnlock()
54+
55+
println("GetSecretCache: ", name)
5256

5357
if IsExpired(secret.CacheData.CacheExpiry) || refresh == "1" {
58+
println("GetSecretCache: refresh")
5459
mutex.Lock()
5560
secretCache[name] = Secret{
5661
CacheData: CacheData{

0 commit comments

Comments
 (0)