mirror of
https://github.com/openvk/chandler.git
synced 2025-04-01 05:54:00 +03:00
Removing all the caching and external dependencies.
This commit is contained in:
parent
c4e87066e2
commit
a4dd0c40ed
1 changed files with 5 additions and 33 deletions
|
@ -1,39 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
use Symfony\Component\Yaml\Yaml;
|
|
||||||
use Nette\Caching\Storages\FileStorage;
|
|
||||||
use Nette\Caching\Cache;
|
|
||||||
|
|
||||||
$GLOBALS["ymlCaFS"] = new FileStorage(CHANDLER_ROOT . "/tmp/cache/yaml");
|
|
||||||
$GLOBALS["ymlCa"] = new Cache($GLOBALS["ymlCaFS"]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses YAML from file.
|
* @param string $filePath
|
||||||
* Caches result on disk to enhance speed.
|
*
|
||||||
* Developers are encouraged to use this function for parsing their YAML data.
|
* @return array
|
||||||
*
|
|
||||||
* @api
|
|
||||||
* @author kurotsun <celestine@vriska.ru>
|
|
||||||
* @param string $filename Path to file
|
|
||||||
* @return array Array
|
|
||||||
*/
|
*/
|
||||||
function chandler_parse_yaml(string $filename): array
|
function chandler_parse_yaml(string $filePath): array
|
||||||
{
|
{
|
||||||
$cache = $GLOBALS["ymlCa"];
|
return yaml_parse_file($filePath);
|
||||||
$id = sha1($filename);
|
|
||||||
|
|
||||||
$result = $cache->load($id);
|
|
||||||
if(!$result) {
|
|
||||||
if(function_exists("yaml_parse_file"))
|
|
||||||
$result = yaml_parse_file($filename);
|
|
||||||
else
|
|
||||||
$result = Yaml::parseFile($filename);
|
|
||||||
|
|
||||||
$cache->save($id, $result, [
|
|
||||||
Cache::EXPIRE => "1 day",
|
|
||||||
Cache::SLIDING => TRUE,
|
|
||||||
Cache::FILES => $filename,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue