Allow connection to cache CMDL definitions. Adjustable via duration if you're not sure how likely CMDL changes occur.

@param $duration
191252
public function enableCmdlCaching($duration = null)
    {
        if ($duration == null) {
            $duration = $this->duration;
        }
        $this->cmdlCaching = $duration;

        $checkLastModifiedDate = false;
        if ($this->hasLastModifiedCacheStrategy()) {
            $checkLastModifiedDate = true;
        }

        $this->readConnection->enableCMDLCaching($duration, $checkLastModifiedDate);
        if ($this->writeConnection) {
            $this->writeConnection->enableCMDLCaching($duration, $checkLastModifiedDate);
        }
    }
439513
public function refreshIfOld($durationInMillis = 0)
    {
        if ($this->getRefreshTimestamp() < ((round(microtime(true) * 1000)) - (integer) $durationInMillis)) {
            $this->refresh();
        }
    }
1290015
public function set_data_to_cache($value, $option = null, $duration = 0)
    {
        return $this->getDatabox()->set_data_to_cache($value, $this->get_cache_key($option), $duration);
    }
1358270
public void addGetTimeNanos(long duration) {
        for (;;) {
            long nanos = getCacheTimeTakenNanos;
            if (nanos <= Long.MAX_VALUE - duration) {
                if (GET_CACHE_TIME_TAKEN_NANOS.compareAndSet(this, nanos, nanos + duration)) {
                    return;
                }
            } else {
                //counter full. Just reset.
                if (GET_CACHE_TIME_TAKEN_NANOS.compareAndSet(this, nanos, duration)) {
                    clear();
                    return;
                }
            }
        }
    }
434044
public static function duration ($duration)
		{
			if (is_numeric($duration))
			{
				$negative = ( $duration < 0 );
				if ($negative)
					$duration = -$duration;

				if (strpos($duration, '.') === false)
					list($seconds, $tail) = [ $duration, 0 ];
				else
					list($seconds, $tail) = explode('.', $duration);

				$dt = new \DateTime('@0');
				$dt2 = new \DateTime("@" . $seconds);

				return ( $negative ? '-' : '' ) . $dt->diff($dt2)->format('%H:%I:%S') . '.' . str_pad($tail, 3, '0', STR_PAD_RIGHT);
			}

			return null;
		}
971133
public function stop(int $duration = null)
    {
        // Stop the Timer
        $this->timer->stop();

        // Store Summary
        $this->summary['duration']  = $duration ?? round($this->timer->getDurationInMilliseconds(), 3);
        $this->summary['headers']   = (function_exists('xdebug_get_headers') === true) ? xdebug_get_headers() : [];
        $this->summary['backtrace'] = debug_backtrace($this->backtraceLimit);
    }
541394
public function select($query, $args = array(), $cache = null, $duration = null)
    {
        if ($this->connection) {
            if ($this->pre_cache($result, $cache)) {
                return $result;
            }

            Profiler::start('query', 'database');
            $result = $this->connection->select($query, $args, true);
            Profiler::stop('query');
            return $this->cache($result, $cache, $duration);
        }
        throw new \Exception('Database connection is not open!');
    }
1300222
protected function limit($connection, $limit)
    {
        $this->logger->notice(sprintf(
            'Limiting connection %s: %s',
            $connection->getIp(),
            $limit
        ));

        $connection->close(new RateLimiterException($limit));
    }
603124
protected function setTimeout(CommandInterface $command, array $definition)
    {
        if (isset($definition[static::CONFIG_TIMEOUT])) {
            $command->setTimeout($definition[static::CONFIG_TIMEOUT]);
        }
    }
1015844
public function writeDuration(QtiDuration $duration)
    {
        try {
            $this->writeString($duration->__toString());
        } catch (BinaryStreamAccessException $e) {
            $msg = "An error occured while writing a duration.";
            throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DURATION, $e);
        }
    }
12505
protected function _writeFile($content, $duration) {
		//$cacheTime = date('Y-m-d H:i:s', $timestamp);
		$now = time();
		if (!$duration) {
			$cacheTime = 0;
		} elseif (is_numeric($duration)) {
			$cacheTime = $now + $duration;
		} else {
			$cacheTime = strtotime($duration, $now);
		}

		$url = $this->request->here();
		$url = str_replace($this->request->base, '', $url);
		if ($url === '/') {
			$url = '_root';
		}

		$cache = $url;
		$prefix = Configure::read('Cache.prefix');
		if ($prefix) {
			$cache = $prefix . '_' . $url;
		}
		if ($url !== '_root') {
			$cache = Inflector::slug($cache);
		}
		if (empty($cache)) {
			return false;
		}

		$ext = $this->response->mapType($this->response->type());
		$content = $this->_compress($content, $ext);

		$cache = $cache . '.html';
		$content = '<!--cachetime:' . $cacheTime . ';ext:' . $ext . '-->' . $content;

		$folder = CACHE . 'views' . DS;
		if (Configure::read('debug') && !is_dir($folder)) {
			mkdir($folder, 0770, true);
		}
		$file = $folder . $cache;

		return file_put_contents($file, $content);
	}
714691
public static function createFromEndAndDuration(Date $end, Duration $duration)
    {
        return static::create($end->sub($duration), $end);
    }
89080
public function getTotal($duration = null)
    {
        $total = User::getDb()->cache(function ($db) {
            return User::find()->count();
        }, $duration);
        return $total;
    }
556546
protected function _initCache()
    {
        if (!Cache::getConfig(static::$cacheConfig)) {
            Cache::setConfig(static::$cacheConfig, [
                'className' => $this->_getDefaultCacheConfigClassName(),
                'prefix' => static::$cacheConfig . '_' . $this->_identifier,
                'duration' => $this->getConfig('interval'),
            ]);
        }
    }
600748
public static function formatDuration($duration, $precision = 3)
    {
        if ($duration < 1) {
            $duration *= 1000;
            $unit = 'ms';
        } else {
            $unit = 's ';
        }

        return self::toPrecision($duration, $precision) . $unit;
    }
658878
public function put($key, $value, $duration, $localOnly = false)
    {
        $cacheKey = $this->cacheKey($key);
        if($this->keepLocalCache)
            $this->localCache[$cacheKey] = $value;
        if(!$localOnly)
            $this->cacheStore->put($cacheKey, $value, $duration);
    }
1018985
public function setDuration(TimeInterface $duration): AlarmInterface
    {
        $this->attributes["Duration"] = $duration->asString();

        return $this->save();
    }