Failed Conditions
Pull Request — master (#10)
by Maximo
03:08
created

library/Providers/CacheDataProvider.php (1 issue)

1
<?php
0 ignored issues
show
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
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 6
    public function register(DiInterface $container)
17
    {
18 6
        $container->setShared(
19 6
            'cache',
20
            function () {
21 2
                $prefix = 'data';
22 2
                $frontAdapter = Data::class;
23
                $frontOptions = [
24 2
                    'lifetime' => envValue('CACHE_LIFETIME', 86400),
25
                ];
26
                $backOptions = [
27 2
                    'servers' => [
28
                        0 => [
29 2
                            'host' => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'),
30 2
                            'port' => envValue('DATA_API_MEMCACHED_PORT', 11211),
31 2
                            '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 2
                    'lifetime' => 3600,
39 2
                    'prefix' => $prefix . '-',
40
                ];
41
42 2
                return new Libmemcached(new $frontAdapter($frontOptions), $backOptions);
43 6
            }
44
        );
45 6
    }
46
}
47