mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 03:56:37 +00:00
Use sync package from unofficial Go library
Uses the sync package from the unofficial Go library instead of simpler solution. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
This commit is contained in:
committed by
Alex Ellis
parent
6ed0ab71fb
commit
01841f605c
@ -6,13 +6,15 @@ package scaling
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"golang.org/x/sync/singleflight"
|
||||
)
|
||||
|
||||
type CachedFunctionQuery struct {
|
||||
cache FunctionCacher
|
||||
serviceQuery ServiceQuery
|
||||
emptyAnnotations map[string]string
|
||||
singleFlight *SingleFlight
|
||||
singleFlight *singleflight.Group
|
||||
}
|
||||
|
||||
func NewCachedFunctionQuery(cache FunctionCacher, serviceQuery ServiceQuery) FunctionQuery {
|
||||
@ -20,7 +22,7 @@ func NewCachedFunctionQuery(cache FunctionCacher, serviceQuery ServiceQuery) Fun
|
||||
cache: cache,
|
||||
serviceQuery: serviceQuery,
|
||||
emptyAnnotations: map[string]string{},
|
||||
singleFlight: NewSingleFlight(),
|
||||
singleFlight: &singleflight.Group{},
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +43,7 @@ func (c *CachedFunctionQuery) Get(fn string, ns string) (ServiceQueryResponse, e
|
||||
query, hit := c.cache.Get(fn, ns)
|
||||
if !hit {
|
||||
key := fmt.Sprintf("GetReplicas-%s.%s", fn, ns)
|
||||
queryResponse, err := c.singleFlight.Do(key, func() (interface{}, error) {
|
||||
queryResponse, err, _ := c.singleFlight.Do(key, func() (interface{}, error) {
|
||||
log.Printf("Cache miss - run GetReplicas")
|
||||
// If there is a cache miss, then fetch the value from the provider API
|
||||
return c.serviceQuery.GetReplicas(fn, ns)
|
||||
|
Reference in New Issue
Block a user