Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit c256f61

Browse files
committed
Here are the docs !!
1 parent 5581feb commit c256f61

File tree

5 files changed

+1507
-2
lines changed

5 files changed

+1507
-2
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
}

Docs/Example/app/AppKernel.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
use Symfony\Component\HttpKernel\Kernel;
4+
use Symfony\Component\Config\Loader\LoaderInterface;
5+
6+
class AppKernel extends Kernel
7+
{
8+
public function registerBundles()
9+
{
10+
$bundles = [
11+
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
12+
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
13+
new Symfony\Bundle\TwigBundle\TwigBundle(),
14+
new Symfony\Bundle\MonologBundle\MonologBundle(),
15+
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
16+
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
17+
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
18+
new AppBundle\AppBundle(),
19+
/**
20+
* PhpFastCache Bundle
21+
*/
22+
new phpFastCache\Bundle\phpFastCacheBundle(),
23+
];
24+
25+
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
26+
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
27+
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
28+
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
29+
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
30+
}
31+
32+
return $bundles;
33+
}
34+
35+
public function getRootDir()
36+
{
37+
return __DIR__;
38+
}
39+
40+
public function getCacheDir()
41+
{
42+
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
43+
}
44+
45+
public function getLogDir()
46+
{
47+
return dirname(__DIR__).'/var/logs';
48+
}
49+
50+
public function registerContainerConfiguration(LoaderInterface $loader)
51+
{
52+
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
53+
}
54+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# PhpFastCache configuration
2+
php_fast_cache:
3+
drivers:
4+
filecache:
5+
type: Files
6+
parameters:
7+
path: %kernel.cache_dir%/phpfastcache/
8+
memcachecache:
9+
type: Memcache
10+
parameters: []
11+
apccache:
12+
type: Apc
13+
parameters: []
14+
sqlitecache:
15+
type: Sqlite
16+
parameters:
17+
path: %kernel.cache_dir%/phpfastcache2/
18+
rediscache:
19+
type: Redis
20+
parameters: []
21+
mongodbcache:
22+
type: Mongodb
23+
parameters:
24+
host: '127.0.0.1'
25+
port: '27017'
26+
username: ''
27+
password: ''
28+
timeout: '1'
29+
couchbasecache:
30+
type: Couchbase
31+
parameters:
32+
host: 'couchbase.host.net'
33+
port: '11211'
34+
username: 'The_Username'
35+
password: 'The_Password'
36+
timeout: '1'
37+
buckets:
38+
-
39+
bucket: 'Cache'
40+
password: 'couchbase-test'
41+
leveldbcache:
42+
type: Leveldb
43+
parameters:
44+
path: %kernel.cache_dir%/phpfastcache_leveldb/
45+
securityKey: optionnalSetting
46+
ssdbcache:
47+
type: Ssdb
48+
parameters: []
49+
apcucache:
50+
type: Apcu
51+
parameters: []
52+
xcachecache:
53+
type: Xcache
54+
parameters: []
55+
devnullcache:
56+
type: Devnull
57+
parameters: []

README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1-
# phpfastcache-bundle
1+
# Symfony 3 PhpFastCache Bundle
2+
3+
4+
#### :thumbsup: Step 1: Include phpFastCache Bundle in your project with composer:
5+
6+
```bash
7+
composer require phpfastcache/phpfastcache-bundle
8+
```
9+
10+
#### :construction: Step 2: Setup your config.yml to configure your cache(s) instance(s)
11+
12+
13+
```yml
14+
# PhpFastCache configuration
15+
php_fast_cache:
16+
drivers:
17+
filecache:
18+
type: Files
19+
parameters:
20+
path: %kernel.cache_dir%/phpfastcache/
21+
```
22+
* More examples in Docs/Example/app/config
23+
24+
##### :wrench: Setup your AppKernel.php by adding the phpFastCache Bundle
25+
26+
```php
27+
$bundles[] = new phpFastCache\Bundle\phpFastCacheBundle();
28+
```
29+
30+
* See the file Docs/Example/app/AppKernel.php for more information.
31+
32+
#### :rocket: Accelerate your app by making use of PhpFastCache service
33+
34+
```php
35+
public function indexAction(Request $request)
36+
{
37+
$cache = $this->get('phpfastcache')->get('filecache');
38+
$item = $cache->getItem('myAppData');
39+
40+
if (!$item->isHit() || $item->get() === null) {
41+
$item->set('Wy app has now superpowers !!')->expiresAfter(3600);//1 hour
42+
$cache->save($item);
43+
}
44+
45+
// replace this example code with whatever you need
46+
return $this->render('default/index.html.twig', [
47+
'myAppData' => $item->get(),
48+
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'),
49+
]);
50+
}
51+
```
52+
53+
#### :boom: phpFastCache Bundle support
54+
Found an issue or had an idea ? Come here [here](https://github.com/PHPSocialNetwork/phpfastcache-bundle/issues) and let us know !
255

3-
Readme will be completed coming soon...

0 commit comments

Comments
 (0)