| 53 | } |
| 54 | |
| 55 | func appsAutoCompleteCache(ctx context.Context) ([]*scalingo.App, error) { |
| 56 | fd, err := os.Open(appsCacheFile) |
| 57 | if err != nil { |
| 58 | return nil, errors.Wrapf(ctx, err, "open apps cache file %s", appsCacheFile) |
| 59 | } |
| 60 | defer fd.Close() |
| 61 | var cache appsCache |
| 62 | err = gob.NewDecoder(fd).Decode(&cache) |
| 63 | if err != nil { |
| 64 | return nil, errors.Wrap(ctx, err, "decode apps cache file") |
| 65 | } |
| 66 | |
| 67 | if time.Since(cache.CreatedAt).Seconds() > appsCacheDuration { |
| 68 | return nil, errExpiredCache |
| 69 | } |
| 70 | |
| 71 | return cache.Apps, nil |
| 72 | } |
| 73 | |
| 74 | func writeAppsAutoCompleteCache(ctx context.Context, apps []*scalingo.App) error { |
| 75 | fd, err := os.OpenFile(appsCacheFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) |