Skip to content

💾 GetCacheDir

Gets the Composer cache directory path, equivalent to running composer config cache-dir.

When to use

Use it when you need to clear the cache, inspect cache usage, or locate cached dependency packages. The cache directory is typically located in the system temporary directory or under COMPOSER_HOME.

Signature

go
func (c *Composer) GetCacheDir() (string, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return valuestringAbsolute path of the Composer cache directory
Second return valueerrorReturned when executing composer config cache-dir 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("initialization failed: %v", err)
	}

	cacheDir, err := comp.GetCacheDir()
	if err != nil {
		log.Fatalf("failed to get cache directory: %v", err)
	}
	fmt.Printf("Composer cache directory: %s\n", cacheDir)
}

Advanced

  • To clear the cache, use ClearCache.
  • To get the Composer home directory (COMPOSER_HOME), use GetComposerHomeDir.
  • To get the vendor directory, use GetVendorDir.

Released under the MIT License