-
Notifications
You must be signed in to change notification settings - Fork 2
/
cache.php
76 lines (76 loc) · 1.79 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require "vendor/autoload.php";
use Phpcraft\Phpcraft;
echo "Phpcraft Cache Utility\n\n";
if(empty($argv))
{
die("This is for PHP-CLI. Connect to your server via SSH and use `php cache.php`.\n");
}
if(!Phpcraft::$json_cache->data)
{
die("Nothing's cached.\n");
}
switch(@$argv[1])
{
case "list":
$has_expired = false;
echo count(Phpcraft::$json_cache->data)." cache entries:\n";
foreach(Phpcraft::$json_cache->data as $url => $entry)
{
echo $url." — ";
$time_til_expire = $entry["expiry"] - time();
if($time_til_expire <= 0)
{
echo "expired\n";
$has_expired = true;
}
else
{
echo "expires in ";
if($time_til_expire > 86400)
{
$days = floor($time_til_expire / 86400);
echo $days."d";
$time_til_expire -= ($days * 86400);
}
if($time_til_expire > 3600)
{
$hours = floor($time_til_expire / 3600);
echo $hours."h";
$time_til_expire -= ($hours * 3600);
}
if($time_til_expire > 60)
{
$mins = floor($time_til_expire / 60);
echo $mins."m";
$time_til_expire -= ($mins * 60);
}
echo $time_til_expire."s\n";
}
}
if($has_expired)
{
echo "Run `php cache.php maintain` to remove expired entries.\n";
}
break;
case "maintain":
echo "Cache entries — before: ".count(Phpcraft::$json_cache->data)."\n";
Phpcraft::maintainCache();
if(file_exists("src/.json_cache"))
{
echo "Cache entries — after: ".count(Phpcraft::$json_cache->data)."\n";
}
else
{
echo "Cache entries — after: 0\n";
}
break;
case "purge":
echo "Cache entries — before: ".count(Phpcraft::$json_cache->data)."\n";
Phpcraft::$json_cache->data = [];
Phpcraft::$json_cache->save();
echo "Cache entries — after: 0\n";
break;
default:
echo "Usage: php cache.php <list|maintain|purge>\n";
}