| 1 |
lars |
1 |
--TEST--
|
|
|
2 |
Cache_Lite::Cache_Lite_Function (dont cache)
|
|
|
3 |
--FILE--
|
|
|
4 |
<?php
|
|
|
5 |
|
|
|
6 |
require_once('callcache.inc');
|
|
|
7 |
require_once('tmpdir.inc');
|
|
|
8 |
require_once('cache_lite_function_base.inc');
|
|
|
9 |
|
|
|
10 |
// Classical
|
|
|
11 |
$options = array(
|
|
|
12 |
'cacheDir' => tmpDir() . '/',
|
|
|
13 |
'lifeTime' => 60,
|
|
|
14 |
'debugCacheLiteFunction' => true
|
|
|
15 |
);
|
|
|
16 |
$cache = new Cache_Lite_Function($options);
|
|
|
17 |
$data = $cache->call('function_test', 23, 66);
|
|
|
18 |
echo($data);
|
|
|
19 |
$data = $cache->call('function_test', 23, 66);
|
|
|
20 |
echo($data);
|
|
|
21 |
$cache->clean();
|
|
|
22 |
|
|
|
23 |
// Don't Cache if output contains NOCACHE
|
|
|
24 |
$options = array(
|
|
|
25 |
'cacheDir' => tmpDir() . '/',
|
|
|
26 |
'lifeTime' => 60,
|
|
|
27 |
'debugCacheLiteFunction' => true,
|
|
|
28 |
'dontCacheWhenTheOutputContainsNOCACHE' => true
|
|
|
29 |
);
|
|
|
30 |
$cache = new Cache_Lite_Function($options);
|
|
|
31 |
$data = $cache->call('function_test2', 23, 66);
|
|
|
32 |
echo($data);
|
|
|
33 |
$data = $cache->call('function_test2', 23, 66);
|
|
|
34 |
echo($data);
|
|
|
35 |
$data = $cache->call('function_test2', 0, 66);
|
|
|
36 |
echo($data);
|
|
|
37 |
$data = $cache->call('function_test2', 0, 66);
|
|
|
38 |
echo($data);
|
|
|
39 |
$cache->clean();
|
|
|
40 |
|
|
|
41 |
// Don't cache if result if false
|
|
|
42 |
$options = array(
|
|
|
43 |
'cacheDir' => tmpDir() . '/',
|
|
|
44 |
'lifeTime' => 60,
|
|
|
45 |
'debugCacheLiteFunction' => true,
|
|
|
46 |
'dontCacheWhenTheResultIsFalse' => true
|
|
|
47 |
);
|
|
|
48 |
$cache = new Cache_Lite_Function($options);
|
|
|
49 |
$data = $cache->call('function_test', 23, 66);
|
|
|
50 |
echo($data);
|
|
|
51 |
$data = $cache->call('function_test', 23, 66);
|
|
|
52 |
echo($data);
|
|
|
53 |
$data = $cache->call('function_test', 0, 66);
|
|
|
54 |
echo($data);
|
|
|
55 |
$data = $cache->call('function_test', 0, 66);
|
|
|
56 |
echo($data);
|
|
|
57 |
$cache->clean();
|
|
|
58 |
|
|
|
59 |
// Don't cache if result if null
|
|
|
60 |
$options = array(
|
|
|
61 |
'cacheDir' => tmpDir() . '/',
|
|
|
62 |
'lifeTime' => 60,
|
|
|
63 |
'debugCacheLiteFunction' => true,
|
|
|
64 |
'dontCacheWhenTheResultIsNull' => true
|
|
|
65 |
);
|
|
|
66 |
$cache = new Cache_Lite_Function($options);
|
|
|
67 |
$data = $cache->call('function_test', 23, 66);
|
|
|
68 |
echo($data);
|
|
|
69 |
$data = $cache->call('function_test', 23, 66);
|
|
|
70 |
echo($data);
|
|
|
71 |
$data = $cache->call('function_test', 1, 66);
|
|
|
72 |
echo($data);
|
|
|
73 |
$data = $cache->call('function_test', 1, 66);
|
|
|
74 |
echo($data);
|
|
|
75 |
$cache->clean();
|
|
|
76 |
|
|
|
77 |
function function_test($arg1, $arg2)
|
|
|
78 |
{
|
|
|
79 |
echo "This is the output of the function function_test($arg1, $arg2) !\n";
|
|
|
80 |
if ($arg1==0) {
|
|
|
81 |
return false;
|
|
|
82 |
}
|
|
|
83 |
if ($arg1==1) {
|
|
|
84 |
return null;
|
|
|
85 |
}
|
|
|
86 |
return '';
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
function function_test2($arg1, $arg2)
|
|
|
90 |
{
|
|
|
91 |
if ($arg1==0) {
|
|
|
92 |
echo "NOCACHE";
|
|
|
93 |
}
|
|
|
94 |
return "This is the result of the function function_test2($arg1, $arg2) !\n";
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
?>
|
|
|
98 |
--GET--
|
|
|
99 |
--POST--
|
|
|
100 |
--EXPECT--
|
|
|
101 |
Cache missed !
|
|
|
102 |
This is the output of the function function_test(23, 66) !
|
|
|
103 |
Cache hit !
|
|
|
104 |
This is the output of the function function_test(23, 66) !
|
|
|
105 |
Cache missed !
|
|
|
106 |
This is the result of the function function_test2(23, 66) !
|
|
|
107 |
Cache hit !
|
|
|
108 |
This is the result of the function function_test2(23, 66) !
|
|
|
109 |
Cache missed !
|
|
|
110 |
This is the result of the function function_test2(0, 66) !
|
|
|
111 |
Cache missed !
|
|
|
112 |
This is the result of the function function_test2(0, 66) !
|
|
|
113 |
Cache missed !
|
|
|
114 |
This is the output of the function function_test(23, 66) !
|
|
|
115 |
Cache hit !
|
|
|
116 |
This is the output of the function function_test(23, 66) !
|
|
|
117 |
Cache missed !
|
|
|
118 |
This is the output of the function function_test(0, 66) !
|
|
|
119 |
Cache missed !
|
|
|
120 |
This is the output of the function function_test(0, 66) !
|
|
|
121 |
Cache missed !
|
|
|
122 |
This is the output of the function function_test(23, 66) !
|
|
|
123 |
Cache hit !
|
|
|
124 |
This is the output of the function function_test(23, 66) !
|
|
|
125 |
Cache missed !
|
|
|
126 |
This is the output of the function function_test(1, 66) !
|
|
|
127 |
Cache missed !
|
|
|
128 |
This is the output of the function function_test(1, 66) !
|