-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputCache.php
More file actions
87 lines (74 loc) · 1.95 KB
/
Copy pathOutputCache.php
File metadata and controls
87 lines (74 loc) · 1.95 KB
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
77
78
79
80
81
82
83
84
85
86
<?php
namespace plugins\riCache;
/**
* Output CoreCache extension of base caching class
*/
class OutputCache extends CoreCache
{
/**
* Group of currently being recorded data
* @var string
*/
private static $group;
/**
* ID of currently being recorded data
* @var string
*/
private static $id;
/**
* Ttl of currently being recorded data
* @var int
*/
private static $ttl;
/**
* Starts caching off. Returns true if cached, and dumps
* the output. False if not cached and start output buffering.
*
* @param string $group Group to store data under
* @param string $id Unique ID of this data
* @param int $ttl How long to cache for (in seconds)
* @return bool True if cached, false if not
*/
public static function Start($group, $id, $ttl)
{
if (self::isCached($group, $id)) {
$data = self::read($group, $id);
if(self::$gzip_level > 0)
$data = gzcompress($data);
echo $data;
return true;
} else {
ob_start();
self::$group = $group;
self::$id = $id;
self::$ttl = $ttl;
return false;
}
}
/**
* Ends caching. Writes data to disk.
*/
public static function End()
{
$data = ob_get_contents();
ob_end_flush();
if (self::$gzip_level > 0) {
$size = strlen($data);
$crc = crc32($data);
$data = gzcompress($data, self::$gzip_level);
// $data = substr($data, 0, strlen($data) - 4);
// $data .= pack('V',$crc);
// $data .= pack('V',$size);
}
self::write(self::$group, self::$id, self::$ttl, $data);
}
/**
* gzuncompress() may not decompress some compressed strings and return a Data Error.
* The problem could be that the outside compressed string has a CRC32 checksum at the end of the file instead of Adler-32
*/
protected function gzuncompress_crc32($data) {
$f = tempnam('/tmp', 'gz_fix');
file_put_contents($f, "\x1f\x8b\x08\x00\x00\x00\x00\x00" . $data);
return file_get_contents('compress.zlib://' . $f);
}
}