Caches container info for 5 seconds before updating it

This commit is contained in:
Katie Knister 2014-12-16 17:29:14 -08:00
parent cc0e999bed
commit cd8a7923ae

View File

@ -44,6 +44,8 @@ type containerData struct {
storageDriver storage.StorageDriver storageDriver storage.StorageDriver
lock sync.Mutex lock sync.Mutex
housekeepingInterval time.Duration housekeepingInterval time.Duration
lastUpdatedTime time.Time
// Whether to log the usage of this container when it is updated. // Whether to log the usage of this container when it is updated.
logUsage bool logUsage bool
@ -63,8 +65,8 @@ func (c *containerData) Stop() error {
} }
func (c *containerData) GetInfo() (*containerInfo, error) { func (c *containerData) GetInfo() (*containerInfo, error) {
// TODO(vmarmol): Consider caching this.
// Get spec and subcontainers. // Get spec and subcontainers.
if time.Since(c.lastUpdatedTime) > 5 * time.Second {
err := c.updateSpec() err := c.updateSpec()
if err != nil { if err != nil {
return nil, err return nil, err
@ -73,7 +75,8 @@ func (c *containerData) GetInfo() (*containerInfo, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
c.lastUpdatedTime = time.Now()
}
// Make a copy of the info for the user. // Make a copy of the info for the user.
c.lock.Lock() c.lock.Lock()
defer c.lock.Unlock() defer c.lock.Unlock()