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:
parent
ce00c6f869
commit
1a2a48e129
1 changed files with 2 additions and 28 deletions
|
@ -25,7 +25,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
|
||||||
if(file_exists($filepath)){
|
if(file_exists($filepath)){
|
||||||
$this->debugMessage('loading cached file from ' . $filepath . ' for page at url ' . $url);
|
$this->debugMessage('loading cached file from ' . $filepath . ' for page at url ' . $url);
|
||||||
// TODO touch file and its parent, and try to do neighbour deletion
|
// TODO touch file and its parent, and try to do neighbour deletion
|
||||||
$this->refresh_in_cache($filepath);
|
touch($filepath);
|
||||||
$content = file_get_contents($filepath);
|
$content = file_get_contents($filepath);
|
||||||
} else {
|
} else {
|
||||||
$this->debugMessage('we have no local copy of ' . $url . ' Downloading to ' . $filepath);
|
$this->debugMessage('we have no local copy of ' . $url . ' Downloading to ' . $filepath);
|
||||||
|
@ -55,34 +55,8 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
|
||||||
return filectime($filepath);
|
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){
|
private function buildCacheFilePath($url){
|
||||||
$cacheDir = __DIR__ . '/../cache/pages/';
|
return __DIR__ . '/../cache/pages/' . sha1($url) . '.cache';
|
||||||
|
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove_from_cache($url){
|
public function remove_from_cache($url){
|
||||||
|
|
Loading…
Reference in a new issue