public static function template($file, array $options = []) {
		$cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates';
		$defaults = ['path' => $cachePath, 'fallback' => false];
		$options += $defaults;

		$stats = stat($file);

		$oname  = basename(dirname($file)) . '_' . basename($file, '.php');
		$oname .= '_' . ($stats['ino'] ?: hash('md5', $file));

		$template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php";
		$template = "{$options['path']}/{$template}";

		if (file_exists($template)) {
			return $template;
		}
		$compiled = static::compile(file_get_contents($file));

		if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) {
			foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) {
				if ($expired !== $template) {
					unlink($expired);
				}
			}
			return $template;
		}
		if ($options['fallback']) {
			return $file;
		}
		throw new TemplateException("Could not write compiled template `{$template}` to cache.");
	}