Cache

Cache caches an Action for a given duration.

carapace.ActionCallback(func(c carapace.Context) carapace.Action {
	return carapace.ActionValues(
		time.Now().Format("15:04:05"),
	)
}).Cache(5 * time.Second)

Caches are implicitly assigned a unique key using runtime.Caller which can change between releases.

Key

Additional keys like key.String can be passed as well.

carapace.ActionMultiParts("/", func(c carapace.Context) carapace.Action {
	switch len(c.Parts) {
	case 0:
		return carapace.ActionValues("one", "two").Suffix("/")
	case 1:
		return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
			return carapace.ActionValues(
				time.Now().Format("15:04:05"),
			)
		}).Cache(10*time.Second, key.String(c.Parts[0]))
	default:
		return carapace.ActionValues()
	}
})

Location

Cache is written as json to os.UserCacheDir using the Export format.

{{cacheDir}}/carapace/{{binary}}/{{callerChecksum}}/{{cacheChecksum}}
IDxexample
cacheDiros.UserCacheDir~/.cache/
binarybinary namecarapace
callerChecksumsha1sum using runtime.Caller89be88b670885d3d7855c7169ad7cfd2816a6c37
cacheChecksumsh1sum of given CacheKeys041858daaaa8b084122d4604a3223315c39edc3e