forked from johnwarne/reddit-top-rss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.php
49 lines (48 loc) · 1.19 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
<?php
// Create cache directories if they don't exist and remove expired cache files
if(CACHE_REDDIT_JSON == true) {
if (!file_exists("cache/reddit")) {
mkdir("cache/reddit", 0755, true);
}
// Remove Reddit JSON files older than 5 minutes
$dir = "cache/reddit/";
foreach (glob($dir . "*") as $file) {
if(time() - filectime($file) > 60 * 5) {
unlink($file);
}
}
if (!file_exists("cache/scores")) {
mkdir("cache/scores", 0755, true);
}
// Remove score files older than 1 hour
$dir = "cache/scores/";
foreach (glob($dir . "*") as $file) {
if(time() - filectime($file) > 60 * 60) {
unlink($file);
}
}
}
if(CACHE_MERCURY_CONTENT == true) {
if (!file_exists("cache/mercury")) {
mkdir("cache/mercury", 0755, true);
}
// Remove Mercury JSON files older than 7 days
$dir = "cache/mercury/";
foreach (glob($dir . "*") as $file) {
if(time() - filectime($file) > 60 * 60 * 24 * 7) {
unlink($file);
}
}
}
if(CACHE_RSS_FEEDS == true) {
if (!file_exists("cache/rss")) {
mkdir("cache/rss", 0755, true);
}
// Remove RSS feed files older than 1 hour
$dir = "cache/rss/";
foreach (glob($dir . "*") as $file) {
if(time() - filectime($file) > 60 * 60 ) {
unlink($file);
}
}
}