1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class BuildTaskTestCache extends BuildTask |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
protected $title = 'Test Silverstripe Cache'; |
6
|
|
|
|
7
|
|
|
protected $description = ' |
8
|
|
|
Basic test for the Sillverstripe Cache. |
9
|
|
|
It will show the date and time the cache was made.'; |
10
|
|
|
|
11
|
|
|
public function run($request) |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
$cache = SS_Cache::factory('foo'); |
14
|
|
|
$result = $cache->load('bar'); |
15
|
|
|
if (!$result || isset($_GET['reload'])) { |
16
|
|
|
$time = time(); |
17
|
|
|
for ($i = 1; $i < $time; $i = $i + 75) { |
18
|
|
|
$temp = $time / $time - rand(0, 10); |
|
|
|
|
19
|
|
|
} |
20
|
|
|
$result = date('Y-m-d H:i:s'); |
21
|
|
|
; |
22
|
|
|
DB::alteration_message('not from cache: '.$result, 'deleted'); |
23
|
|
|
$cache->save($result, 'bar'); |
24
|
|
|
} else { |
25
|
|
|
DB::alteration_message('from cache: '.$result, 'created'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if (isset($_GET['setm'])) { |
29
|
|
|
foreach (array('11211', '11212', '11213', '11214') as $port) { |
30
|
|
|
echo "<h1>SETTING: $port</h1>"; |
31
|
|
|
$memcache = new Memcache; |
32
|
|
|
$cacheAvailable = $memcache->connect('127.0.0.1', $port); |
33
|
|
|
if ($cacheAvailable) { |
34
|
|
|
$memcache->set('test_memcache', 'set at: '.date('Y-m-d H:i:s')); |
35
|
|
|
echo "SET"; |
36
|
|
|
} else { |
37
|
|
|
echo "NOT SET"; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} elseif (isset($_GET['getm'])) { |
41
|
|
|
foreach (array('11211', '11212', '11213', '11214') as $port) { |
42
|
|
|
echo "<h1>GETTING: $port</h1>"; |
43
|
|
|
$memcache = new Memcache; |
44
|
|
|
$cacheAvailable = $memcache->connect('127.0.0.1', $port); |
45
|
|
|
if ($cacheAvailable) { |
46
|
|
|
$outcome = $memcache->get('test_memcache'); |
47
|
|
|
echo $outcome; |
48
|
|
|
} else { |
49
|
|
|
echo "COULD NOT GET"; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.