mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 00:54:41 +00:00
add cache helper function in config.inc, needed for https://github.com/opnsense/core/issues/3567
get_cached_json_content() deserialize json data when the file is found and not yet expired, returns null otherwise. Since there might be some spots in the code where this can be convenient, it seemed like a good idea to wrap it in a function within the legacy code base. Maybe config.inc is not enterily the right spot for this, but util.inc is quite diverse already.
This commit is contained in:
parent
a6cd706755
commit
292358b9e5
@ -301,6 +301,22 @@ function legacy_config_get_interfaces($filters = array())
|
||||
return $interfaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse stored json content, return empty when not found or expired
|
||||
*/
|
||||
function get_cached_json_content($filename, $ttl=3600)
|
||||
{
|
||||
$result = null;
|
||||
if (file_exists($filename)) {
|
||||
$fstat = stat($filename);
|
||||
if ((time() - $fstat['mtime']) < $ttl) {
|
||||
$result = json_decode(file_get_contents($filename), true);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
$config = parse_config();
|
||||
|
||||
/* set timezone */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user