1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | |||
3 | namespace Gewaer\Providers; |
||
4 | |||
5 | use function Gewaer\Core\envValue; |
||
6 | use Phalcon\Cache\Backend\Libmemcached; |
||
7 | use Phalcon\Cache\Frontend\Data; |
||
8 | use Phalcon\Di\ServiceProviderInterface; |
||
9 | use Phalcon\DiInterface; |
||
10 | |||
11 | class CacheDataProvider implements ServiceProviderInterface |
||
12 | { |
||
13 | /** |
||
14 | * @param DiInterface $container |
||
15 | */ |
||
16 | public function register(DiInterface $container) |
||
17 | { |
||
18 | $container->setShared( |
||
19 | 'cache', |
||
20 | function () { |
||
21 | $prefix = 'data'; |
||
22 | $frontAdapter = Data::class; |
||
23 | $frontOptions = [ |
||
24 | 'lifetime' => envValue('CACHE_LIFETIME', 86400), |
||
25 | ]; |
||
26 | $backOptions = [ |
||
27 | 'servers' => [ |
||
28 | 0 => [ |
||
29 | 'host' => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'), |
||
30 | 'port' => envValue('DATA_API_MEMCACHED_PORT', 11211), |
||
31 | 'weight' => envValue('DATA_API_MEMCACHED_WEIGHT', 100), |
||
32 | ], |
||
33 | ], |
||
34 | 'client' => [ |
||
35 | \Memcached::OPT_HASH => \Memcached::HASH_MD5, |
||
36 | \Memcached::OPT_PREFIX_KEY => 'api-', |
||
37 | ], |
||
38 | 'lifetime' => 3600, |
||
39 | 'prefix' => $prefix . '-', |
||
40 | ]; |
||
41 | |||
42 | return new Libmemcached(new $frontAdapter($frontOptions), $backOptions); |
||
43 | } |
||
44 | ); |
||
45 | } |
||
46 | } |
||
47 |