🧹 ClearCache
Clears Composer's download and metadata cache. Equivalent to running composer clear-cache.
When to use
Use when you encounter package download anomalies, expired metadata, or need to ensure dependencies are pulled from a clean state in CI. Also commonly used for disk space reclamation.
Signature
go
func (c *Composer) ClearCache() errorParameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| Sole return value | error | Returned when clearing fails |
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatalf("init failed: %v", err)
}
if err := comp.ClearCache(); err != nil {
log.Fatalf("failed to clear cache: %v", err)
}
fmt.Println("Composer cache cleared")
}Advanced
- To view the cache directory location before clearing, use GetComposerHome or
GetCacheDir(). - This method only cares about the exit code and does not return the command text output.
- In automation pipelines, it is typically called once before retrying a failed
Update/Installto rule out cache contamination.