You are here

public function CompanyMembershipObjectCache::saveMembership in Apigee Edge 8

Saves company membership object to the cache.

Parameters

string $company: Name of a company.

\Apigee\Edge\Api\Management\Structure\CompanyMembership $membership: Membership object with the members.

Overrides CompanyMembershipObjectCacheInterface::saveMembership

File

modules/apigee_edge_teams/src/CompanyMembershipObjectCache.php, line 100

Class

CompanyMembershipObjectCache
Providers a persistent & non-persistent cache for company membership objects.

Namespace

Drupal\apigee_edge_teams

Code

public function saveMembership(string $company, CompanyMembership $membership) : void {
  $expiration = $this->persistentCacheExpiration;

  // Do not save in cache, if expiration is set to 0.
  if (0 === $expiration) {
    return;
  }

  // Tag company membership cache entries with members' (developers') email
  // addresses for easier cache invalidation when a developer gets removed.
  $tags = [];
  foreach (array_keys($membership
    ->getMembers()) as $developer_email) {
    $tags[] = "developer:{$developer_email}";
  }
  $this->memoryCache
    ->set($company, $membership, CacheBackendInterface::CACHE_PERMANENT, $tags);
  if ($expiration !== CacheBackendInterface::CACHE_PERMANENT) {
    $expiration = $this->systemTime
      ->getCurrentTime() + $expiration;
  }
  $this->persistentCacheBackend
    ->set($company, $membership, $expiration, $tags);
}