MCPcopy
hub / github.com/openfaas/faas / Get

Method Get

gateway/scaling/function_query.go:43–74  ·  view source on GitHub ↗
(fn string, ns string)

Source from the content-addressed store, hash-verified

41}
42
43func (c *CachedFunctionQuery) Get(fn string, ns string) (ServiceQueryResponse, error) {
44
45 query, hit := c.cache.Get(fn, ns)
46 if !hit {
47 key := fmt.Sprintf("GetReplicas-%s.%s", fn, ns)
48 queryResponse, err, _ := c.singleFlight.Do(key, func() (interface{}, error) {
49 log.Printf("Cache miss - run GetReplicas")
50 // If there is a cache miss, then fetch the value from the provider API
51 return c.serviceQuery.GetReplicas(fn, ns)
52 })
53
54 if err != nil {
55 return ServiceQueryResponse{}, err
56 }
57
58 if queryResponse != nil {
59 c.cache.Set(fn, ns, queryResponse.(ServiceQueryResponse))
60 }
61
62 } else {
63 return query, nil
64 }
65
66 // At this point the value almost certainly must be present, so if not
67 // return an error.
68 query, hit = c.cache.Get(fn, ns)
69 if !hit {
70 return ServiceQueryResponse{}, fmt.Errorf("error with cache key: %s", fn+"."+ns)
71 }
72
73 return query, nil
74}
75
76type FunctionQuery interface {
77 Get(name string, namespace string) (ServiceQueryResponse, error)

Callers 1

GetAnnotationsMethod · 0.95

Calls 4

DoMethod · 0.80
GetMethod · 0.65
GetReplicasMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected