77
88namespace Drupal \memcache ;
99
10- use Drupal \Component \ Utility \ Crypt ;
10+ use Drupal \Core \ Cache \ Cache ;
1111use Drupal \Core \Cache \CacheBackendInterface ;
1212use Drupal \Core \Cache \CacheTagsChecksumInterface ;
1313use Drupal \Core \Lock \LockBackendInterface ;
1717 */
1818class MemcacheBackend implements CacheBackendInterface {
1919
20+ use MemcacheCacheNormalizer;
21+
2022 /**
2123 * The cache bin to use.
2224 *
@@ -245,7 +247,7 @@ public function deleteAll() {
245247 * {@inheritdoc}
246248 */
247249 public function invalidate ($ cid ) {
248- $ this ->invalidateMultiple ([ $ cid] );
250+ $ this ->invalidateMultiple (( array ) $ cid );
249251 }
250252
251253 /**
@@ -257,10 +259,10 @@ public function invalidate($cid) {
257259 * @param array $cids
258260 * An array of cache IDs to invalidate.
259261 *
260- * @see \ Drupal\Core\Cache\CacheBackendInterface::deleteMultiple()
261- * @see \ Drupal\Core\Cache\CacheBackendInterface::invalidate()
262- * @see \ Drupal\Core\Cache\CacheBackendInterface::invalidateTags()
263- * @see \ Drupal\Core\Cache\CacheBackendInterface::invalidateAll()
262+ * @see Drupal\Core\Cache\CacheBackendInterface::deleteMultiple()
263+ * @see Drupal\Core\Cache\CacheBackendInterface::invalidate()
264+ * @see Drupal\Core\Cache\CacheBackendInterface::invalidateTags()
265+ * @see Drupal\Core\Cache\CacheBackendInterface::invalidateAll()
264266 */
265267 public function invalidateMultiple (array $ cids ) {
266268 foreach ($ cids as $ cid ) {
@@ -308,32 +310,6 @@ public function isEmpty() {
308310 return TRUE ;
309311 }
310312
311- /**
312- * Normalizes a cache ID in order to comply with database limitations.
313- *
314- * The lock still uses the database so must comply with limitations.
315- *
316- * @param string $cid
317- * The passed in cache ID.
318- *
319- * @return string
320- * An ASCII-encoded cache ID that is at most 255 characters long.
321- */
322- protected function normalizeCid ($ cid ) {
323- // Nothing to do if the ID is a US ASCII string of 255 characters or less.
324- $ cid_is_ascii = mb_check_encoding ($ cid , 'ASCII ' );
325- if (strlen ($ cid ) <= 255 && $ cid_is_ascii ) {
326- return $ cid ;
327- }
328- // Return a string that uses as much as possible of the original cache ID
329- // with the hash appended.
330- $ hash = Crypt::hashBase64 ($ cid );
331- if (!$ cid_is_ascii ) {
332- return $ hash ;
333- }
334- return substr ($ cid , 0 , 255 - strlen ($ hash )) . $ hash ;
335- }
336-
337313 /**
338314 * Returns a cache key prefixed with the current bin.
339315 *
@@ -342,7 +318,7 @@ protected function normalizeCid($cid) {
342318 * @return string
343319 */
344320 protected function key ($ cid ) {
345- return $ this ->normalizeCid ($ this ->bin . '- ' . $ cid );
321+ return $ this ->normalizeKey ($ this ->bin . '- ' . $ cid );
346322 }
347323
348324}
0 commit comments