buildkit/build_llb/cache_store.go
buildkit/build_llb/cache_store.goBrowse 1970 files
264 tokens
903 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package build_llb2 3import (4 "fmt"5 6 "github.com/moby/buildkit/client/llb"7 "github.com/railwayapp/railpack/core/plan"8)9 10type BuildKitCache struct {11 cacheKey string12 planCache *plan.Cache13 cacheState *llb.State14}15 16type BuildKitCacheStore struct {17 uniqueID string18 CacheMap map[string]BuildKitCache19}20 21func NewBuildKitCacheStore(uniqueID string) *BuildKitCacheStore {22 return &BuildKitCacheStore{23 uniqueID: uniqueID,24 CacheMap: make(map[string]BuildKitCache),25 }26}27 28func (c *BuildKitCacheStore) GetCache(key string, planCache *plan.Cache) BuildKitCache {29 cacheKey := key30 if c.uniqueID != "" {31 cacheKey = fmt.Sprintf("%s-%s", c.uniqueID, key)32 }33 34 if cache, ok := c.CacheMap[cacheKey]; ok {35 return cache36 }37 38 cacheState := llb.Scratch()39 40 cache := BuildKitCache{41 cacheKey: cacheKey,42 planCache: planCache,43 cacheState: &cacheState,44 }45 46 c.CacheMap[cacheKey] = cache47 48 return cache49}50