@@ -62,24 +62,14 @@ func (c *Cache) Put(pkg *packages.Package, mode HashMode, key string, data any)
6262 return err
6363 }
6464
65- var aID cache.ActionID
66-
67- c .sw .TrackStage ("key build" , func () {
68- aID , err = c .pkgActionID (pkg , mode )
69- if err == nil {
70- subkey , subkeyErr := cache .Subkey (aID , key )
71- if subkeyErr != nil {
72- err = fmt .Errorf ("failed to build subkey: %w" , subkeyErr )
73- }
74- aID = subkey
75- }
76- })
65+ actionID , err := c .buildKey (pkg , mode , key )
7766 if err != nil {
7867 return fmt .Errorf ("failed to calculate package %s action id: %w" , pkg .Name , err )
7968 }
69+
8070 c .ioSem <- struct {}{}
8171 c .sw .TrackStage ("cache io" , func () {
82- err = cache .PutBytes (c .lowLevelCache , aID , buf .Bytes ())
72+ err = cache .PutBytes (c .lowLevelCache , actionID , buf .Bytes ())
8373 })
8474 <- c .ioSem
8575 if err != nil {
@@ -90,26 +80,15 @@ func (c *Cache) Put(pkg *packages.Package, mode HashMode, key string, data any)
9080}
9181
9282func (c * Cache ) Get (pkg * packages.Package , mode HashMode , key string , data any ) error {
93- var aID cache.ActionID
94- var err error
95- c .sw .TrackStage ("key build" , func () {
96- aID , err = c .pkgActionID (pkg , mode )
97- if err == nil {
98- subkey , subkeyErr := cache .Subkey (aID , key )
99- if subkeyErr != nil {
100- err = fmt .Errorf ("failed to build subkey: %w" , subkeyErr )
101- }
102- aID = subkey
103- }
104- })
83+ actionID , err := c .buildKey (pkg , mode , key )
10584 if err != nil {
10685 return fmt .Errorf ("failed to calculate package %s action id: %w" , pkg .Name , err )
10786 }
10887
10988 var b []byte
11089 c .ioSem <- struct {}{}
11190 c .sw .TrackStage ("cache io" , func () {
112- b , _ , err = cache .GetBytes (c .lowLevelCache , aID )
91+ b , _ , err = cache .GetBytes (c .lowLevelCache , actionID )
11392 })
11493 <- c .ioSem
11594 if err != nil {
@@ -122,6 +101,22 @@ func (c *Cache) Get(pkg *packages.Package, mode HashMode, key string, data any)
122101 return c .decode (b , data )
123102}
124103
104+ func (c * Cache ) buildKey (pkg * packages.Package , mode HashMode , key string ) (cache.ActionID , error ) {
105+ return timeutils .TrackStage [cache.ActionID ](c .sw , "key build" , func () (cache.ActionID , error ) {
106+ actionID , err := c .pkgActionID (pkg , mode )
107+ if err != nil {
108+ return actionID , err
109+ }
110+
111+ subkey , subkeyErr := cache .Subkey (actionID , key )
112+ if subkeyErr != nil {
113+ return actionID , fmt .Errorf ("failed to build subkey: %w" , subkeyErr )
114+ }
115+
116+ return subkey , nil
117+ })
118+ }
119+
125120func (c * Cache ) pkgActionID (pkg * packages.Package , mode HashMode ) (cache.ActionID , error ) {
126121 hash , err := c .packageHash (pkg , mode )
127122 if err != nil {
0 commit comments