Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
function callCache($id, $type = 'string') {
4
    global $Cache_Lite;
5
    if ($data = $Cache_Lite->get($id)) {
6
        echo("Cache Hit !\n");
7
        if ($type=='string') {
8
            echo($data);
9
        }
10
        if ($type=='array') {
11
            echo(serialize($data));
12
        }
13
    } else {
14
        echo("Cache Missed !\n");
15
        if ($type=='string') {
16
            $data = '';
17
            for($i=0;$i<10;$i++) {
18
                $data .= '0123456789';
19
            }
20
            echo($data);
21
        }
22
        if ($type=='array') {
23
            $data = array(array('foo', 'bar'), 1, 'foo', 'bar');
24
            echo(serialize($data));
25
        }
26
        $res = $Cache_Lite->save($data);
27
        if (is_object($res)) {
28
            echo "\nPEAR_ERROR : " . $res->getMessage() . " (#" . $res->getCode() . ")\n";
29
        } else {
30
	        if (!($res)) {
31
	            echo "\nError when saving cache !\n";
32
	        }
33
        }
34
    }
35
}
36
 
37
function multipleCallCache($type = 'string') {
38
    global $Cache_Lite;
39
 
40
    echo "==> First call (cache should be missed)\n";
41
    callCache('31415926', $type);
42
    echo "\nDone !\n\n";
43
 
44
    echo "==> Second call (cache should be hit)\n";
45
    callCache('31415926', $type);
46
    echo "\nDone !\n\n";
47
 
48
    echo "==> Third call (cache should be hit)\n";
49
    callCache('31415926', $type);
50
    echo "\nDone !\n\n";
51
 
52
    echo "==> We remove cache\n";
53
    $Cache_Lite->remove('31415926');
54
    echo "Done !\n\n";
55
 
56
    echo "==> Fourth call (cache should be missed)\n";
57
    callCache('31415926', $type);
58
    echo "\nDone !\n\n";
59
 
60
    echo "==> #5 Call with another id (cache should be missed)\n";
61
    callCache('3141592653', $type);
62
    echo "\nDone !\n\n";
63
 
64
    echo "==> We remove cache\n";
65
    $Cache_Lite->remove('31415926');
66
    $Cache_Lite->remove('3141592653');
67
    echo "Done !\n";
68
}
69
 
70
function callCache2($id, $type = 'string') {
71
    global $Cache_Lite_Output;
72
    if (!($Cache_Lite_Output->start($id))) {
73
        if ($type=='string') {
74
            $data = '';
75
            for($i=0;$i<10;$i++) {
76
                $data .= '0123456789';
77
            }
78
            echo($data);
79
        }
80
        if ($type=='array') {
81
            $data = array(array('foo', 'bar'), 1, 'foo', 'bar');
82
            echo(serialize($data));
83
        }
84
        $Cache_Lite_Output->end();
85
        echo("Cache Missed !\n");
86
    } else {
87
        echo("Cache Hit !\n");
88
    }
89
}
90
 
91
function multipleCallCache2($type = 'string') {
92
    global $Cache_Lite_Output;
93
 
94
    echo "==> First call (cache should be missed)\n";
95
    callCache2('31415926', $type);
96
    echo "\nDone !\n\n";
97
 
98
    echo "==> Second call (cache should be hit)\n";
99
    callCache2('31415926', $type);
100
    echo "\nDone !\n\n";
101
 
102
    echo "==> Third call (cache should be hit)\n";
103
    callCache2('31415926', $type);
104
    echo "\nDone !\n\n";
105
 
106
    echo "==> We remove cache\n";
107
    $Cache_Lite_Output->remove('31415926');
108
    echo "Done !\n\n";
109
 
110
    echo "==> Fourth call (cache should be missed)\n";
111
    callCache2('31415926', $type);
112
    echo "\nDone !\n\n";
113
 
114
    echo "==> #5 Call with another id (cache should be missed)\n";
115
    callCache2('3141592653', $type);
116
    echo "\nDone !\n\n";
117
 
118
    echo "==> We remove cache\n";
119
    $Cache_Lite_Output->remove('31415926');
120
    $Cache_Lite_Output->remove('3141592653');
121
    echo "Done !\n";
122
}
123
 
124
function multipleCallCache3_1($type = 'string') {
125
    global $Cache_Lite;
126
 
127
    echo "==> #6 call (cache should be missed)\n";
128
    callCache('31415926', $type);
129
    echo "\nDone !\n\n";
130
 
131
    echo "==> #7 call (cache should be hit)\n";
132
    callCache('31415926', $type);
133
    echo "\nDone !\n\n";
134
}
135
 
136
function multipleCallCache3_2($type = 'string') {
137
    global $Cache_Lite;
138
 
139
    echo "==> #8 call (cache should be missed)\n";
140
    callCache('31415926', $type);
141
    echo "\nDone !\n\n";
142
 
143
    echo "==> We remove cache\n";
144
    $Cache_Lite->remove('31415926');
145
    echo "Done !\n";
146
 
147
}
148
 
149
?>