@@ -265,6 +265,23 @@ public function blockSubmit($form, FormStateInterface $form_state) {
265265 $ this ->setConfiguration ($ updated_config + $ configuration );
266266 // Invalidate the block cache to update custom block-based derivatives.
267267 $ this ->blockManager ->clearCachedDefinitions ();
268+ // Invalidate custom cache.
269+ // @todo Replace with cache_backend->set().
270+ $ language = \Drupal::languageManager ()->getCurrentLanguage ();
271+ $ context = $ this ->getContextValues ();
272+ $ configuration = $ this ->getConfiguration ();
273+ $ pattern_id = $ this ->getDerivativeId ();
274+ $ instance_id = $ configuration ['instance_uuid ' ] ?? $ pattern_id ;
275+ $ cid = "patternkit: {$ pattern_id }: {$ instance_id }: " ;
276+ $ cid .= md5 (
277+ $ this ->serializer ::encode ([
278+ \Drupal::currentUser ()->isAuthenticated (),
279+ $ context ,
280+ $ configuration ,
281+ $ language ->getId (),
282+ ])
283+ );
284+ $ this ->cache ->delete ($ cid );
268285 parent ::blockSubmit ($ form , $ form_state );
269286 }
270287
@@ -288,13 +305,7 @@ public function build() {
288305
289306 // If an instance configuration provides a UUID, use it. If not, we should
290307 // not cache this item because the uuid will be different each time.
291- if (empty ($ configuration ['instance_uuid ' ])) {
292- $ cacheable = FALSE ;
293- $ instance_id = $ this ->getDerivativeId ();
294- }
295- else {
296- $ instance_id = $ configuration ['instance_uuid ' ];
297- }
308+ $ instance_id = $ configuration ['instance_uuid ' ] ?? $ pattern_id ;
298309
299310 // Create the cache key to be used for this object. Note that we are relying
300311 // on code elsewhere to clear this cache on modification. The md5 against
@@ -303,7 +314,7 @@ public function build() {
303314 // logged-in check to prevent cached admin links from appearing in frontend.
304315 // It also mitigates the difference between esi delivery when logged in vs
305316 // not.
306- // @todo Replace with getCacheTags().
317+ // @todo Replace with getCacheTags() and cache_backend->get() .
307318 $ language = \Drupal::languageManager ()->getCurrentLanguage ();
308319 $ cid = "patternkit: {$ pattern_id }: {$ instance_id }: " ;
309320 $ cid .= md5 (
@@ -330,7 +341,7 @@ public function build() {
330341
331342 // Initialize our static (if necessary).
332343 if ($ is_processed === NULL ) {
333- $ is_processed = array () ;
344+ $ is_processed = [] ;
334345 }
335346
336347 // If we've already processed this module, don't add it to active again.
@@ -352,12 +363,12 @@ public function build() {
352363 }
353364
354365 // If the item is cache-able, fetch it and return it.
355- if ($ cacheable === TRUE ) {
356- // Attempt to fetch the cached pane .
357- $ cached = $ this ->cache ->get ($ cid, ' cache_patternkit ' );
366+ if ($ cacheable ) {
367+ // Attempt to fetch the cached block .
368+ $ cached = $ this ->cache ->get ($ cid );
358369 if ($ cached !== FALSE ) {
359370
360- // Set flag to let other modules know content is patternkit stuff .
371+ // Set flag to let other modules know content is patternkit cache .
361372 $ cached ->patternkit = 1 ;
362373
363374 return $ cached ->data ;
@@ -411,7 +422,7 @@ public function build() {
411422 '#attached ' => $ config ['pkdata ' ]['attachments ' ] ?? [],
412423 ];
413424 // Save to the cache bin (if caching is enabled).
414- if ($ cacheable === TRUE ) {
425+ if ($ cacheable ) {
415426 $ this ->cache ->set ($ cid , $ content , time () + $ ttl , ['cache_patternkit ' ]);
416427 }
417428
0 commit comments