Skip to content

Commit

Permalink
Caches container info for 5 seconds before updating it
Browse files Browse the repository at this point in the history
  • Loading branch information
kateknister committed Dec 17, 2014
1 parent cc0e999 commit cd8a792
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions manager/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type containerData struct {
storageDriver storage.StorageDriver
lock sync.Mutex
housekeepingInterval time.Duration
lastUpdatedTime time.Time


// Whether to log the usage of this container when it is updated.
logUsage bool
Expand All @@ -63,17 +65,18 @@ func (c *containerData) Stop() error {
}

func (c *containerData) GetInfo() (*containerInfo, error) {
// TODO(vmarmol): Consider caching this.
// Get spec and subcontainers.
err := c.updateSpec()
if err != nil {
return nil, err
}
err = c.updateSubcontainers()
if err != nil {
return nil, err
}

if time.Since(c.lastUpdatedTime) > 5 * time.Second {
err := c.updateSpec()
if err != nil {
return nil, err
}
err = c.updateSubcontainers()
if err != nil {
return nil, err
}
c.lastUpdatedTime = time.Now()
}
// Make a copy of the info for the user.
c.lock.Lock()
defer c.lock.Unlock()
Expand Down

0 comments on commit cd8a792

Please sign in to comment.