File tree 2 files changed +48
-0
lines changed
src/DI/ZendFramework2/Service
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,22 @@ return [
121
121
];
122
122
```
123
123
124
+ ### Enable Memcached cache
125
+
126
+ If you're using Memcached, you should have only one project per memcached instance.
127
+
128
+ ``` php
129
+ return [
130
+ 'phpdi-zf2' => [
131
+ 'cache' => [
132
+ 'adapter' => 'memcached',
133
+ 'host' => 'localhost', // default is localhost
134
+ 'port' => 11211, // default is 11211
135
+ ],
136
+ ]
137
+ ];
138
+ ```
139
+
124
140
## Console commands
125
141
126
142
### Clear definition cache
Original file line number Diff line number Diff line change 8
8
use Doctrine \Common \Cache \Cache ;
9
9
use Doctrine \Common \Cache \CacheProvider ;
10
10
use Doctrine \Common \Cache \FilesystemCache ;
11
+ use Doctrine \Common \Cache \MemcachedCache ;
11
12
use Doctrine \Common \Cache \RedisCache ;
12
13
use Zend \ServiceManager \FactoryInterface ;
13
14
use Zend \ServiceManager \ServiceLocatorInterface ;
@@ -60,6 +61,10 @@ public function createService(ServiceLocatorInterface $serviceLocator)
60
61
$ cache = $ this ->getRedisCache ($ config );
61
62
break ;
62
63
64
+ case 'memcached ' :
65
+ $ cache = $ this ->getMemcachedCache ($ config );
66
+ break ;
67
+
63
68
default :
64
69
throw ConfigException::newUnsupportedCacheAdapterException ($ adapter );
65
70
}
@@ -125,4 +130,31 @@ private function getRedisCache(array $config)
125
130
126
131
return $ cache ;
127
132
}
133
+
134
+ /**
135
+ * creates memcached cache
136
+ *
137
+ * @param array $config
138
+ * @return MemcachedCache
139
+ */
140
+ private function getMemcachedCache (array $ config )
141
+ {
142
+ $ host = 'localhost ' ;
143
+ $ port = 11211 ;
144
+
145
+ if (isset ($ config ['host ' ])) {
146
+ $ host = $ config ['host ' ];
147
+ }
148
+
149
+ if (isset ($ config ['port ' ])) {
150
+ $ port = $ config ['port ' ];
151
+ }
152
+
153
+ $ cache = new MemcachedCache ();
154
+ $ memcache = new \Memcached ;
155
+ $ memcache ->addServer ($ host , $ port );
156
+ $ cache ->setMemcached ($ memcache );
157
+
158
+ return $ cache ;
159
+ }
128
160
}
You can’t perform that action at this time.
0 commit comments