Caches container info for 5 seconds before updating it
This commit is contained in:
parent
cc0e999bed
commit
cd8a7923ae
@ -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,17 +65,18 @@ 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.
|
||||||
err := c.updateSpec()
|
if time.Since(c.lastUpdatedTime) > 5 * time.Second {
|
||||||
if err != nil {
|
err := c.updateSpec()
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = c.updateSubcontainers()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.lastUpdatedTime = time.Now()
|
||||||
}
|
}
|
||||||
err = c.updateSubcontainers()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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()
|
||||||
|
Loading…
Reference in New Issue
Block a user