22
33namespace Illuminate \Cache ;
44
5+ use Memcached ;
56use Illuminate \Contracts \Cache \Store ;
67
78class MemcachedStore extends TaggableStore implements Store
@@ -48,6 +49,34 @@ public function get($key)
4849 }
4950 }
5051
52+ /**
53+ * Retrieve multiple items from the cache by key.
54+ *
55+ * Items not found in the cache will have a null value for the key.
56+ *
57+ * @param array $keys
58+ * @return array
59+ */
60+ public function getMultiple (array $ keys )
61+ {
62+ $ prefixedKeys = [];
63+
64+ foreach ($ keys as $ keyToPrefix ) {
65+ $ prefixedKeys [] = $ this ->prefix .$ keyToPrefix ;
66+ }
67+
68+ $ cas = null ;
69+ $ cacheValues = $ this ->memcached ->getMulti ($ prefixedKeys , $ cas , Memcached::GET_PRESERVE_ORDER );
70+
71+ if ($ this ->memcached ->getResultCode () != 0 ) {
72+ return array_fill_keys ($ keys , null );
73+ }
74+
75+ $ returnValues = array_combine ($ keys , $ cacheValues );
76+
77+ return $ returnValues ;
78+ }
79+
5180 /**
5281 * Store an item in the cache for a given number of minutes.
5382 *
@@ -61,6 +90,24 @@ public function put($key, $value, $minutes)
6190 $ this ->memcached ->set ($ this ->prefix .$ key , $ value , $ minutes * 60 );
6291 }
6392
93+ /**
94+ * Store multiple items in the cache for a set number of minutes.
95+ *
96+ * @param array $values
97+ * @param int $minutes
98+ * @return void
99+ */
100+ public function putMultiple (array $ values , $ minutes )
101+ {
102+ $ formattedKeyValues = [];
103+
104+ foreach ($ values as $ keyToPrefix => $ singleValue ) {
105+ $ formattedKeyValues [$ this ->prefix .$ keyToPrefix ] = $ singleValue ;
106+ }
107+
108+ $ this ->memcached ->setMulti ($ formattedKeyValues , $ minutes * 60 );
109+ }
110+
64111 /**
65112 * Store an item in the cache if the key doesn't exist.
66113 *
0 commit comments