@@ -265,6 +265,23 @@ public function blockSubmit($form, FormStateInterface $form_state) {
265
265
$ this ->setConfiguration ($ updated_config + $ configuration );
266
266
// Invalidate the block cache to update custom block-based derivatives.
267
267
$ 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 );
268
285
parent ::blockSubmit ($ form , $ form_state );
269
286
}
270
287
@@ -288,13 +305,7 @@ public function build() {
288
305
289
306
// If an instance configuration provides a UUID, use it. If not, we should
290
307
// 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 ;
298
309
299
310
// Create the cache key to be used for this object. Note that we are relying
300
311
// on code elsewhere to clear this cache on modification. The md5 against
@@ -303,7 +314,7 @@ public function build() {
303
314
// logged-in check to prevent cached admin links from appearing in frontend.
304
315
// It also mitigates the difference between esi delivery when logged in vs
305
316
// not.
306
- // @todo Replace with getCacheTags().
317
+ // @todo Replace with getCacheTags() and cache_backend->get() .
307
318
$ language = \Drupal::languageManager ()->getCurrentLanguage ();
308
319
$ cid = "patternkit: {$ pattern_id }: {$ instance_id }: " ;
309
320
$ cid .= md5 (
@@ -330,7 +341,7 @@ public function build() {
330
341
331
342
// Initialize our static (if necessary).
332
343
if ($ is_processed === NULL ) {
333
- $ is_processed = array () ;
344
+ $ is_processed = [] ;
334
345
}
335
346
336
347
// If we've already processed this module, don't add it to active again.
@@ -352,12 +363,12 @@ public function build() {
352
363
}
353
364
354
365
// 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 );
358
369
if ($ cached !== FALSE ) {
359
370
360
- // Set flag to let other modules know content is patternkit stuff .
371
+ // Set flag to let other modules know content is patternkit cache .
361
372
$ cached ->patternkit = 1 ;
362
373
363
374
return $ cached ->data ;
@@ -411,7 +422,7 @@ public function build() {
411
422
'#attached ' => $ config ['pkdata ' ]['attachments ' ] ?? [],
412
423
];
413
424
// Save to the cache bin (if caching is enabled).
414
- if ($ cacheable === TRUE ) {
425
+ if ($ cacheable ) {
415
426
$ this ->cache ->set ($ cid , $ content , time () + $ ttl , ['cache_patternkit ' ]);
416
427
}
417
428
0 commit comments