-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosekaiCache.php
70 lines (65 loc) · 1.82 KB
/
osekaiCache.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
<?php
class Caching
{
/**
* @param mixed $name
*
* @return [type]
*/
public static function getCache($name)
{
Caching::cleanCache();
$caches = Database::execSelect("SELECT * FROM GlobalCache WHERE Title = ? ORDER BY Date", "s", [$name]);
if ($caches == null || count($caches) == 0) {
return null;
}
$cache = $caches[0]['Data'];
return $cache;
}
/**
* @param mixed $name
* @param mixed $expiry
* @param mixed $data
*
* @return [type]
*/
public static function saveCache($name, $expiry, $data)
{
// remove all with existing name
Database::execOperation("DELETE FROM GlobalCache WHERE Title = ?", "s", [$name]);
// if expiry is not a date, it is a number of seconds
if (is_numeric($expiry)) {
$expiry = date("Y-m-d H:i:s", time() + $expiry);
} else {
$expiry = $expiry;
}
Database::execOperation("INSERT INTO GlobalCache (Title, Expiration, Data, Date) VALUES (?, ?, ?, CURRENT_TIMESTAMP)", "sss", [$name, $expiry, $data]);
}
/**
* @return [type]
*/
public static function cleanCache()
{
// removes expired caches
Database::execSimpleOperation("DELETE FROM GlobalCache WHERE Expiration < CURRENT_TIMESTAMP");
}
/**
* @param mixed $cacheName
*
* @return [type]
*/
public static function wipeCache($cacheName)
{
Database::execOperation("DELETE FROM GlobalCache WHERE Title = ?", "s", [$cacheName]);
}
/**
* @param mixed $prefix
*
* @return [type]
*/
public static function wipeCacheFromPrefix($prefix)
{
Database::execOperation("DELETE FROM GlobalCache WHERE Title LIKE ?", "s", [$prefix . "%"]);
}
}
?>