You are here

final class DeveloperCompaniesCache in Apigee Edge 8

Default non-persistent developer company membership cache implementation.

Hierarchy

Expanded class hierarchy of DeveloperCompaniesCache

1 string reference to 'DeveloperCompaniesCache'
apigee_edge.services.yml in ./apigee_edge.services.yml
apigee_edge.services.yml
1 service uses DeveloperCompaniesCache
apigee_edge.controller.cache.developer_companies in ./apigee_edge.services.yml
Drupal\apigee_edge\Entity\DeveloperCompaniesCache

File

src/Entity/DeveloperCompaniesCache.php, line 29

Namespace

Drupal\apigee_edge\Entity
View source
final class DeveloperCompaniesCache implements DeveloperCompaniesCacheInterface {

  /**
   * The memory cache backend.
   *
   * @var \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface
   */
  private $backend;

  /**
   * DeveloperCompaniesCache constructor.
   *
   * @param \Drupal\apigee_edge\MemoryCacheFactoryInterface $memory_cache_factory
   *   The memory cache factory service.
   */
  public function __construct(MemoryCacheFactoryInterface $memory_cache_factory) {
    $this->backend = $memory_cache_factory
      ->get('developer_companies');
  }

  /**
   * {@inheritdoc}
   */
  public function getCompanies(string $id) : ?array {
    $item = $this->backend
      ->get($id);
    return $item ? $item->data : NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function saveCompanies(array $developers) : void {

    /** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface $developer */
    foreach ($developers as $developer) {
      $tags = array_merge([
        "developer:{$developer->getDeveloperId()}",
        "developer:{$developer->getEmail()}",
      ], array_map(function (string $company) {
        return "company:{$company}";
      }, $developer
        ->getCompanies()));
      $this->backend
        ->set($developer
        ->id(), $developer
        ->getCompanies(), CacheBackendInterface::CACHE_PERMANENT, $tags);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function remove(array $ids = []) : void {
    if (empty($ids)) {
      $this->backend
        ->invalidateAll();
    }
    else {
      $this->backend
        ->invalidateMultiple($ids);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function invalidate(array $tags) : void {
    $this->backend
      ->invalidateTags($tags);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeveloperCompaniesCache::$backend private property The memory cache backend.
DeveloperCompaniesCache::getCompanies public function Returns companies of a developer. Overrides DeveloperCompaniesCacheInterface::getCompanies
DeveloperCompaniesCache::invalidate public function Invalidates cache entries by tag. Overrides DeveloperCompaniesCacheInterface::invalidate
DeveloperCompaniesCache::remove public function Removes cached company information of a developer. Overrides DeveloperCompaniesCacheInterface::remove
DeveloperCompaniesCache::saveCompanies public function Saves developers' companies to cache. Overrides DeveloperCompaniesCacheInterface::saveCompanies
DeveloperCompaniesCache::__construct public function DeveloperCompaniesCache constructor.