File tree 4 files changed +32
-62
lines changed 4 files changed +32
-62
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -76,14 +76,20 @@ private function clearFileCache()
76
76
private function clearMemCached ()
77
77
{
78
78
echo 'Clearing data cache ' . PHP_EOL ;
79
- $ options = include appPath ('cli/config/cache.php ' );
79
+ $ options = [];
80
+ if (isset ($ this ->getDI ()->getShared ('config ' )->get ('cache ' )->options ->libmemcached )) {
81
+ $ options = $ this ->getDI ()->getShared ('config ' )->get ('cache ' )->options ->libmemcached ;
82
+ }
83
+
80
84
$ servers = $ options ['servers ' ] ?? [];
81
85
$ memcached = new \Memcached ();
82
86
foreach ($ servers as $ server ) {
83
87
$ memcached ->addServer ($ server ['host ' ], $ server ['port ' ], $ server ['weight ' ]);
84
88
}
85
89
86
90
$ keys = $ memcached ->getAllKeys ();
91
+ // 7.2 countable
92
+ $ keys = $ keys ?: [];
87
93
echo sprintf ('Found %s keys ' , count ($ keys )) . PHP_EOL ;
88
94
foreach ($ keys as $ key ) {
89
95
if ('api-data ' === substr ($ key , 0 , 8 )) {
Original file line number Diff line number Diff line change 27
27
'time ' => microtime (true ),
28
28
],
29
29
'cache ' => [
30
- 'data ' => [
31
- 'front ' => [
32
- 'adapter ' => 'Data ' ,
33
- 'options ' => [
34
- 'lifetime ' => envValue ('CACHE_LIFETIME ' ),
35
- ],
36
- ],
37
- 'back ' => [
38
- 'dev ' => [
39
- 'adapter ' => 'File ' ,
40
- 'options ' => [
41
- 'cacheDir ' => appPath ('storage/cache/data/ ' ),
30
+ 'adapter ' => envValue ('CACHE_ADAPTER ' ),
31
+ 'options ' => [
32
+ 'libmemcached ' => [
33
+ 'servers ' => [
34
+ 0 => [
35
+ 'host ' => envValue ('DATA_API_MEMCACHED_HOST ' , '127.0.0.1 ' ),
36
+ 'port ' => envValue ('DATA_API_MEMCACHED_PORT ' , 11211 ),
37
+ 'weight ' => envValue ('DATA_API_MEMCACHED_WEIGHT ' , 100 ),
42
38
],
43
39
],
44
- 'prod ' => [
45
- 'adapter ' => 'Libmemcached ' ,
46
- 'options ' => [
47
- 'servers ' => [
48
- [
49
- 'host ' => envValue ('DATA_API_MEMCACHED_HOST ' ),
50
- 'port ' => envValue ('DATA_API_MEMCACHED_PORT ' ),
51
- 'weight ' => envValue ('DATA_API_MEMCACHED_WEIGHT ' ),
52
- ],
53
- ],
54
- ],
40
+ 'client ' => [
41
+ \Memcached::OPT_PREFIX_KEY => 'api- ' ,
55
42
],
43
+ 'lifetime ' => envValue ('CACHE_LIFETIME ' , 86400 ),
44
+ 'prefix ' => 'data- ' ,
56
45
],
57
46
],
47
+
58
48
'metadata ' => [
59
49
'dev ' => [
60
50
'adapter ' => 'Memory ' ,
Original file line number Diff line number Diff line change 14
14
15
15
use Phalcon \Cache ;
16
16
use Phalcon \Cache \AdapterFactory ;
17
+ use Phalcon \Config ;
17
18
use Phalcon \Di \DiInterface ;
18
19
use Phalcon \Di \ServiceProviderInterface ;
19
20
use Phalcon \Storage \SerializerFactory ;
20
- use function Phalcon \Api \Core \appPath ;
21
21
22
22
class CacheDataProvider implements ServiceProviderInterface
23
23
{
24
24
/**
25
- * @param DiInterface $container
25
+ * @param DiInterface $di
26
26
*/
27
- public function register (DiInterface $ container ): void
27
+ public function register (DiInterface $ di ): void
28
28
{
29
- $ container ->setShared (
29
+ /** @var Config $config */
30
+ $ config = $ di ->getShared ('config ' );
31
+
32
+ $ di ->setShared (
30
33
'cache ' ,
31
- function () {
32
- /** @var array $backOptions */
33
- $ options = include appPath ('cli/config/cache.php ' );
34
+ function () use ($ config ) {
35
+ $ cache = $ config ->get ('cache ' )->toArray ();
36
+ $ adapter = $ cache ['adapter ' ];
37
+ $ options = $ cache ['options ' ][$ adapter ] ?? [];
34
38
35
39
$ serializerFactory = new SerializerFactory ();
36
40
$ adapterFactory = new AdapterFactory ($ serializerFactory );
37
- $ adapter = $ adapterFactory ->newInstance ($ options [ ' adapter ' ] , $ options );
41
+ $ adapter = $ adapterFactory ->newInstance ($ adapter , $ options );
38
42
39
43
return new Cache ($ adapter );
40
44
}
You can’t perform that action at this time.
0 commit comments