code: func (c *InstanceCache) withState(ctx context.Context, now time.Time, f func(*messages.InstanceCache)) {
  	state := &messages.InstanceCache{}
  
  	start := clock.Now(ctx)
  	defer func() {
  		totalTime := clock.Since(ctx, start)
  		if totalTime > 2*time.Second {
  			logging.Warningf(
  				ctx, "cipd: instance cache state update took %s (%d entries)",
  				totalTime, len(state.Entries))
  		}
  	}()
  
  	c.stateLock.Lock()
  	defer c.stateLock.Unlock()
  
  	c.readState(ctx, state, now)
  	f(state)
  	if err := c.saveState(ctx, state); err != nil {
  		logging.Warningf(ctx, "cipd: could not save instance cache - %s", err)
  	}
  }
docs: // withState loads cache state from the state file, calls f and saves it back.
  // See also readState.