perform caching of jsonld schemas

This commit is contained in:
zotlabs 2017-09-19 19:15:15 -07:00
parent 373af6d4f4
commit b0cdec0c35
2 changed files with 33 additions and 0 deletions

View file

@ -82,6 +82,8 @@ class LDSignatures {
if(! is_object($data))
return '';
jsonld_set_document_loader('jsonld_document_loader');
return jsonld_normalize($data,[ 'algorithm' => 'URDNA2015', 'format' => 'application/nquads' ]);
}

View file

@ -1943,4 +1943,35 @@ function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false) {
}
// no mime-type found
return null;
}
function jsonld_document_loader($url) {
// perform caching for jsonld normaliser
require_once('library/jsonld/jsonld.php');
$cachepath = 'store/[data]/ldcache';
if(! is_dir($cachepath))
os_mkdir($cachepath,STORAGE_DEFAULT_PERMISSIONS,true);
$filename = $cachepath . '/' . urlencode($url);
if(file_exists($filename) && filemtime($filename) > time() - (12 * 60 * 60)) {
return json_decode(file_get_contents($filename));
}
$r = jsonld_default_document_loader($url);
if($r) {
file_put_contents($filename,json_encode($r));
return $r;
}
logger('not found');
if(file_exists($filename)) {
return json_decode(file_get_contents($filename));
}
return [];
}