package main import ( "fmt" "sync" "time" ) var ( IdempotencyStore = make(map[string]string) mu sync.Mutex ) func EnrollCourseIdempotent(key string) string { mu.Lock() if val, ok := IdempotencyStore[key]; ok { mu.Unlock() return fmt.Sprintf("Hasil cache: %s", val) } mu.Unlock() // proses baru fmt.Println("Memproses enrollment baru...") time.Sleep(1500 * time.Millisecond) result := "Enrollment berhasil untuk " + key mu.Lock() IdempotencyStore[key] = result mu.Unlock() return result }