framework/db/Command.php
public function cache($duration = null, $dependency = null)
    {
        $this->queryCacheDuration = $duration === null ? $this->db->queryCacheDuration : $duration;
        $this->queryCacheDependency = $dependency;
        return $this;
    }
public function cache($duration = null, $dependency = null)
    {
        $this->queryCacheDuration = $duration === null ? $this->db->queryCacheDuration : $duration;
        $this->queryCacheDependency = $dependency;
        return $this;
    }
Enables query cache for this command.
@param int $duration the number of seconds that query result of this command can remain valid in the cache.
If this is not set, the value of [[Connection::queryCacheDuration]] will be used instead.
Use 0 to indicate that the cached data will never expire.
@param \yii\caching\Dependency $dependency the cache dependency associated with the cached query result.
@return $this the command object itself