1
0
Fork 0
forked from blallo/rss-bridge

[HttpCachingBridgeAbstract] Use sha1 cache file names

Previously folder hierarchies were created based on the input URL
which could result in very deep folder structures. Using SHA1 file
names also allows to check for old files more effectively (via
fileatime)
This commit is contained in:
logmanoriginal 2016-09-10 00:00:10 +02:00
parent ce00c6f869
commit 1a2a48e129

View file

@ -25,7 +25,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
if(file_exists($filepath)){
$this->debugMessage('loading cached file from ' . $filepath . ' for page at url ' . $url);
// TODO touch file and its parent, and try to do neighbour deletion
$this->refresh_in_cache($filepath);
touch($filepath);
$content = file_get_contents($filepath);
} else {
$this->debugMessage('we have no local copy of ' . $url . ' Downloading to ' . $filepath);
@ -55,34 +55,8 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
return filectime($filepath);
}
private function refresh_in_cache($filepath){
$cacheDir = __DIR__ . '/../cache/pages/';
$currentPath = $filepath;
while(!$cacheDir == $currentPath){
touch($currentPath);
$currentPath = dirname($currentPath);
}
}
private function buildCacheFilePath($url){
$cacheDir = __DIR__ . '/../cache/pages/';
$simplified_url = str_replace(
['http://', 'https://', '?', '&', '='],
['', '', '/', '/', '/'],
$url);
if(substr($cacheDir, -1) !== '/'){
$cacheDir .= '/';
}
$filepath = $cacheDir . $simplified_url;
if(substr($filepath, -1) === '/'){
$filepath .= 'index.html';
}
return realpath($filepath);
return __DIR__ . '/../cache/pages/' . sha1($url) . '.cache';
}
public function remove_from_cache($url){