1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException; |
9
|
|
|
|
10
|
|
|
class DefaultController extends Controller |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @Route("/", name="homepage") |
14
|
|
|
*/ |
15
|
|
|
public function indexAction(Request $request) |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$pfc_test = null; |
|
|
|
|
18
|
|
|
|
19
|
|
|
$cache = $this->get('phpfastcache')->get('filecache'); |
20
|
|
|
$cache2 = $this->get('phpfastcache')->get('memcachecache'); |
21
|
|
|
$cache3 = $this->get('phpfastcache')->get('ssdbcache'); |
22
|
|
|
$cache4 = $this->get('phpfastcache')->get('sqlitecache'); |
23
|
|
|
$cache5 = $this->get('phpfastcache')->get('rediscache'); |
24
|
|
|
$cache6 = $this->get('phpfastcache')->get('mongodbcache'); |
25
|
|
|
$cache7 = $this->get('phpfastcache')->get('couchbasecache'); |
26
|
|
|
$cache8 = $this->get('phpfastcache')->get('leveldbcache'); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Xcache and APC cannot coexists |
30
|
|
|
*/ |
31
|
|
|
try{ |
32
|
|
|
$cache9 = $this->get('phpfastcache')->get('apccache'); |
33
|
|
|
$cache10 = $this->get('phpfastcache')->get('apcucache'); |
34
|
|
|
}catch(PhpfastcacheDriverCheckException $e){ |
35
|
|
|
$cache11 = $this->get('phpfastcache')->get('xcachecache'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$cache12 = $this->get('phpfastcache')->get('devnullcache'); |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
$item = $cache->getItem('test'); |
42
|
|
|
$item1 = $cache->getItem('test2'); |
43
|
|
|
$item2 = $cache2->getItem('test'); |
44
|
|
|
$item3 = $cache3->getItem('test'); |
45
|
|
|
$item4 = $cache4->getItem('test'); |
46
|
|
|
$item5 = $cache5->getItem('test'); |
47
|
|
|
$item6 = $cache6->getItem('test'); |
48
|
|
|
$item7 = $cache7->getItem('test'); |
49
|
|
|
$item8 = $cache7->getItem('test2'); |
50
|
|
|
$item9 = $cache8->getItem('test2'); |
51
|
|
|
|
52
|
|
|
if(isset($cache9) && isset($cache10)) |
53
|
|
|
{ |
54
|
|
|
$item10 = $cache9->getItem('test2'); |
55
|
|
|
$item11 = $cache10->getItem('test2'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if(isset($cache11)) |
59
|
|
|
{ |
60
|
|
|
$item12 = $cache11->getItem('test2'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$item13 = $cache12->getItem('test2'); |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
if ($item->isHit()) { |
68
|
|
|
$pfc_test = $item->get(); |
69
|
|
|
} else { |
70
|
|
|
|
71
|
|
|
$item->set('Loaded from cache')->expiresAfter(10); |
72
|
|
|
$item1->set('Loaded from cache2')->expiresAfter(10); |
73
|
|
|
$item2->set('Loaded from cache +' . str_repeat('*', rand(1000, 5000)))->expiresAfter(10); |
74
|
|
|
$item3->set('Loaded from cache +' . str_repeat('+', rand(1000, 5000)))->expiresAfter(10); |
75
|
|
|
$item4->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
76
|
|
|
$item5->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
77
|
|
|
$item6->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
78
|
|
|
$item7->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
79
|
|
|
$item8->set('Loaded from cache2')->expiresAfter(10); |
80
|
|
|
$item9->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
81
|
|
|
|
82
|
|
|
if(isset($item10) && isset($item11)) |
83
|
|
|
{ |
84
|
|
|
$item10->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
85
|
|
|
$item11->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if(isset($item12)) |
89
|
|
|
{ |
90
|
|
|
$item12->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$item13->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
$cache->save($item); |
97
|
|
|
$cache->save($item1); |
98
|
|
|
$cache2->save($item2); |
99
|
|
|
$cache3->save($item3); |
100
|
|
|
$cache4->save($item4); |
101
|
|
|
$cache5->save($item5); |
102
|
|
|
$cache6->save($item6); |
103
|
|
|
$cache7->save($item7); |
104
|
|
|
$cache7->save($item8); |
105
|
|
|
$cache8->save($item9); |
106
|
|
|
|
107
|
|
|
if(isset($cache9) && isset($cache10)) |
108
|
|
|
{ |
109
|
|
|
$cache9->save($item10); |
|
|
|
|
110
|
|
|
$cache10->save($item11); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if(isset($cache11)) |
114
|
|
|
{ |
115
|
|
|
$cache11->save($item12); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$cache12->save($item13); |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
$pfc_test = 'Not loaded from cache'; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// replace this example code with whatever you need |
125
|
|
|
return $this->render('default/index.html.twig', [ |
126
|
|
|
'pfc_test' => $pfc_test, |
127
|
|
|
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'), |
128
|
|
|
]); |
129
|
|
|
} |
130
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.