-
Notifications
You must be signed in to change notification settings - Fork 2
/
cache.php
38 lines (36 loc) · 874 Bytes
/
cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
function createCache($url,$content) {
global $cache_folder;
$filename = md5($url);
$filepath = $cache_folder . $filename;
$handle = fopen($filepath, "w");
$success = fwrite($handle, $content);
fclose($handle);
return $success;
}
function checkCache($url) {
global $cache_folder, $cache_seconds;
$filename = md5($url);
$filepath = $cache_folder . $filename;
if (!file_exists($filepath)) {
return false;
} else {
$timestamp = filemtime($filepath);
if ($timestamp + $cache_seconds > time()) {
$content = getCache($url);
return $content;
} else {
return false;
}
}
}
function getCache($url) {
global $cache_folder;
$filename = md5($url);
$filepath = $cache_folder . $filename;
$handle = fopen($filepath, "r");
$content = fread($handle, filesize($filepath));
fclose($handle);
return $content;
}
?>