You are here

public function MailCacheBuild::isCacheable in Simplenews 8.2

Same name and namespace in other branches
  1. 8 src/Mail/MailCacheBuild.php \Drupal\simplenews\Mail\MailCacheBuild::isCacheable()
  2. 3.x src/Mail/MailCacheBuild.php \Drupal\simplenews\Mail\MailCacheBuild::isCacheable()

Return if the requested element should be cached.

Parameters

\Drupal\simplenews\Mail\MailInterface $mail: The mail object.

string $group: Group of the cache key, which allows cache implementations to decide what they want to cache. Currently used groups:

  • data: Raw data, e.g. attachments.
  • build: Built and themed content, before personalizations like tokens.
  • final: The final returned data. Caching this means that newsletter can not be personalized anymore.

string $key: Identifies the requested element, e.g. body or attachments.

Return value

bool TRUE if it should be cached, FALSE otherwise.

Overrides MailCacheStatic::isCacheable

File

src/Mail/MailCacheBuild.php, line 15

Class

MailCacheBuild
Source cache implementation that caches build and data element.

Namespace

Drupal\simplenews\Mail

Code

public function isCacheable(MailInterface $mail, $group, $key) {

  // Only cache for anon users.
  if (\Drupal::currentUser()
    ->isAuthenticated()) {
    return FALSE;
  }

  // Only cache data and build information.
  return in_array($group, [
    'data',
    'build',
  ]);
}