You are here

final class AppCache in Apigee Edge 8

Default app cache implementation for app controllers.

See interface definition for more details,

This app cache implementation also keeps an internal list about apps by using using their app owners and app names as an id. The owner information is extracted from the app entity so it is either developer id (UUID) or company name. Developer email address is not acceptable here.

Hierarchy

Expanded class hierarchy of AppCache

1 string reference to 'AppCache'
apigee_edge.services.yml in ./apigee_edge.services.yml
apigee_edge.services.yml
1 service uses AppCache
apigee_edge.controller.cache.apps in ./apigee_edge.services.yml
Drupal\apigee_edge\Entity\Controller\Cache\AppCache

File

src/Entity/Controller/Cache/AppCache.php, line 40

Namespace

Drupal\apigee_edge\Entity\Controller\Cache
View source
final class AppCache extends EntityCache implements AppCacheInterface {

  /**
   * An associative array with app owners, app names and app ids.
   *
   * Parent keys are app owners (developer UUID or company name), second level
   * keys are app names and their values are app ids (UUIDs).
   *
   * This array can contain app ids that have been invalidated
   * in cache. It is not a problem because this information is only used
   * internally.
   *
   * @var array
   */
  private $appOwnerAppNameAppIdMap = [];

  /**
   * {@inheritdoc}
   */
  protected function prepareCacheItem(EntityInterface $entity) : array {

    /** @var \Apigee\Edge\Api\Management\Entity\AppInterface $entity */
    $owner = $this
      ->getAppOwner($entity);
    $item = [
      // We have to cache apps by their app ids here, $entity->id() returns
      // the name of the app.
      $entity
        ->getAppId() => [
        'data' => $entity,
        'tags' => [
          $entity
            ->getAppId(),
          $owner,
        ],
      ],
    ];
    $this->appOwnerAppNameAppIdMap[$owner][$entity
      ->getName()] = $entity
      ->getAppId();
    return $item;
  }

  /**
   * {@inheritdoc}
   */
  public function getAppOwner(AppInterface $app) : string {
    if ($app instanceof DeveloperAppInterface) {
      return $app
        ->getDeveloperId();
    }
    elseif ($app instanceof CompanyAppInterface) {
      return $app
        ->getCompanyName();
    }
    throw new RuntimeException('Unable to identify app owner.');
  }

  /**
   * {@inheritdoc}
   */
  public function getAppsByOwner(string $owner) : ?array {
    if (!empty($this->appOwnerAppNameAppIdMap[$owner])) {
      return $this
        ->getEntities($this->appOwnerAppNameAppIdMap[$owner]);
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function removeAppsByOwner(string $owner) : void {
    if (!empty($this->appOwnerAppNameAppIdMap[$owner])) {
      $this
        ->removeEntities($this->appOwnerAppNameAppIdMap[$owner]);
      unset($this->appOwnerAppNameAppIdMap[$owner]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AppCache::$appOwnerAppNameAppIdMap private property An associative array with app owners, app names and app ids.
AppCache::getAppOwner public function Returns the owner of an app. Overrides AppCacheInterface::getAppOwner
AppCache::getAppsByOwner public function Returns an app from the cache by its owner. Overrides AppCacheInterface::getAppsByOwner
AppCache::prepareCacheItem protected function Generates cache items for an entity. Overrides EntityCache::prepareCacheItem
AppCache::removeAppsByOwner public function Remove all apps from the cache by their owner. Overrides AppCacheInterface::removeAppsByOwner
EntityCache::$allEntitiesInCache private property Indicates whether all entities in the cache or not.
EntityCache::$cacheBackend protected property The memory cache backend used by this cache.
EntityCache::$cacheIds private property Array of entity ids stored in the cache.
EntityCache::$entityIdCache protected property The entity id cache related to this entity type.
EntityCache::allEntitiesInCache final public function Changes whether all entities in the cache or not. Overrides EntityCacheInterface::allEntitiesInCache
EntityCache::doRemoveEntities protected function Allows to perform additional tasks after entities got deleted from cache. 1
EntityCache::doSaveEntities protected function Allows to perform additional tasks after entities got saved to cache. 1
EntityCache::getEntities final public function Returns entities from the cache. Overrides EntityCacheInterface::getEntities
EntityCache::getEntity final public function Returns an entity from the cache by its id. Overrides EntityCacheInterface::getEntity
EntityCache::isAllEntitiesInCache final public function Returns whether all entities in cache or not. Overrides EntityCacheInterface::isAllEntitiesInCache
EntityCache::removeEntities final public function Removes entities from the cache by their ids. Overrides EntityCacheInterface::removeEntities
EntityCache::saveEntities final public function Saves entities to the cache. Overrides EntityCacheInterface::saveEntities
EntityCache::__construct public function EntityCache constructor. 1
EntityCache::__sleep public function Prevents data stored in entity cache from being serialized.