(fn string, ns string)
| 41 | } |
| 42 | |
| 43 | func (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 | |
| 76 | type FunctionQuery interface { |
| 77 | Get(name string, namespace string) (ServiceQueryResponse, error) |
no test coverage detected