Repository: cli/cli
File: pkg/cmd/cache/delete/delete.go (Go)

Code before:
						err = fmt.Errorf("%s Could not find a cache matching %s (with ref %s) in %s", cs.FailureIcon(), cache, opts.Ref, repoName)
					}
				} else {
					err = fmt.Errorf("%s Failed to delete cache: %w", cs.FailureIcon(), err)
				}
			}
			opts.IO.StopProgressIndicator()
			return err
		}

		totalDeleted += count
	}

	opts.IO.StopProgressIndicator()

	if opts.IO.IsStdoutTTY() {
		fmt.Fprintf(opts.IO.Out, "%s Deleted %s from %s\n", cs.SuccessIcon(), text.Pluralize(totalDeleted, "cache"), repoName)
	}

	return nil
}

func deleteCacheByID(client *api.Client, repo ghrepo.Interface, id int) error {
	path := fmt.Sprintf("repos/%s/actions/caches/%d", ghrepo.FullName(repo), id)
	return client.REST(repo.RepoHost(), "DELETE", path, nil, nil)
}

func deleteCacheByKey(client *api.Client, repo ghrepo.Interface, key, ref string) (int, error) {
	path := fmt.Sprintf("repos/%s/actions/caches?key=%s", ghrepo.FullName(repo), url.QueryEscape(key))
	if ref != "" {
		path += fmt.Sprintf("&ref=%s", url.QueryEscape(ref))
	}
	var payload shared.CachePayload
	err := client.REST(repo.RepoHost(), "DELETE", path, nil, &payload)
	if err != nil {
		return 0, err
	}

	return payload.TotalCount, nil
}

func parseCacheID(arg string) (int, bool) {
	id, err := strconv.Atoi(arg)
	return id, err == nil
}


Review comment (performance):
Please add this godoc here:

```suggestion
// deleteCacheByKey deletes cache entries by given key (and optional ref) and
// returns the number of deleted entries.
//
// Note that a key/ref combination does not necessarily map to a single cache
// entry. There may be more than one entries with the same key/ref combination,
// but those entries will have different IDs.
func deleteCacheByKey(client *api.Client, repo ghrepo.Interface, key, ref string) (int, error) {
```

Code after:

		totalDeleted += count
	}

	opts.IO.StopProgressIndicator()

	if opts.IO.IsStdoutTTY() {
		fmt.Fprintf(opts.IO.Out, "%s Deleted %s from %s\n", cs.SuccessIcon(), text.Pluralize(totalDeleted, "cache"), repoName)
	}

	return nil
}

func deleteCacheByID(client *api.Client, repo ghrepo.Interface, id int) error {
	// returns HTTP 204 (NO CONTENT) on success
	path := fmt.Sprintf("repos/%s/actions/caches/%d", ghrepo.FullName(repo), id)
	return client.REST(repo.RepoHost(), "DELETE", path, nil, nil)
}

// deleteCacheByKey deletes cache entries by given key (and optional ref) and
// returns the number of deleted entries.
//
// Note that a key/ref combination does not necessarily map to a single cache
// entry. There may be more than one entries with the same key/ref combination,
// but those entries will have different IDs.
func deleteCacheByKey(client *api.Client, repo ghrepo.Interface, key, ref string) (int, error) {
	path := fmt.Sprintf("repos/%s/actions/caches?key=%s", ghrepo.FullName(repo), url.QueryEscape(key))
	if ref != "" {
		path += fmt.Sprintf("&ref=%s", url.QueryEscape(ref))
	}
	var payload shared.CachePayload
	err := client.REST(repo.RepoHost(), "DELETE", path, nil, &payload)
	if err != nil {
		return 0, err
	}

	return payload.TotalCount, nil
}

func parseCacheID(arg string) (int, bool) {
	id, err := strconv.Atoi(arg)
	return id, err == nil
}