@@ -40,7 +40,7 @@ public function __construct(\Memcached $cache)
4040
4141 protected function fetchObjectFromCache ($ key )
4242 {
43- return $ this ->cache ->get ($ this ->getHierarchyKey ($ key ));
43+ return $ this ->cache ->get ($ this ->trimKey ( $ this -> getHierarchyKey ($ key) ));
4444 }
4545
4646 protected function clearAllObjectsFromCache ()
@@ -51,8 +51,8 @@ protected function clearAllObjectsFromCache()
5151 protected function clearOneObjectFromCache ($ key )
5252 {
5353 $ this ->commit ();
54- $ key = $ this ->getHierarchyKey ($ key , $ path );
55- $ this ->cache ->increment ($ path , 1 , 0 );
54+ $ key = $ this ->trimKey ( $ this -> getHierarchyKey ($ key , $ path) );
55+ $ this ->cache ->increment ($ this -> trimKey ( $ path) , 1 , 0 );
5656 $ this ->clearHierarchyKeyCache ();
5757
5858 if ($ this ->cache ->delete ($ key )) {
@@ -69,13 +69,28 @@ protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
6969 $ ttl = 0 ;
7070 }
7171
72- $ key = $ this ->getHierarchyKey ($ key );
72+ $ key = $ this ->trimKey ( $ this -> getHierarchyKey ($ key) );
7373
7474 return $ this ->cache ->set ($ key , $ item , $ ttl );
7575 }
7676
7777 protected function getValueFormStore ($ key )
7878 {
79- return $ this ->cache ->get ($ key );
79+ return $ this ->cache ->get ($ this ->trimKey ($ key ));
80+ }
81+
82+ /**
83+ * Calculate a key. If it is more than 250 chars we should hash the key.
84+ *
85+ * @param $key
86+ * @param null $ref
87+ */
88+ private function trimKey ($ key )
89+ {
90+ if (strlen ($ key ) < 250 ) {
91+ return $ key ;
92+ }
93+ // This should maybe be logged
94+ return sha1 ($ key );
8095 }
8196}
0 commit comments