public function add($entity, string $id)
    {
        $entityClass = get_class($entity);

        if ($entityClass !== $this->class) {
            throw new CacheException('Tried to cache an instance with a wrong type : expected '.$this->class.", got $entityClass");
        }

        // Cache once and ignore subsequent caching
        // attempts if the entity is already stored
        if (!$this->has($id)) {
            $this->instances[$id] = $entity;
        }
    }
public function add($entity, string $id)
    {
        $entityClass = get_class($entity);

        if ($entityClass !== $this->class) {
            throw new CacheException('Tried to cache an instance with a wrong type : expected '.$this->class.", got $entityClass");
        }

        // Cache once and ignore subsequent caching
        // attempts if the entity is already stored
        if (!$this->has($id)) {
            $this->instances[$id] = $entity;
        }
    }
public function add ( $ entity , string $ id ) { $ entityClass = get_class ( $ entity ) ; if ( $ entityClass !== $ this -> class ) { throw new CacheException ( 'Tried to cache an instance with a wrong type : expected ' . $ this -> class . ", got $entityClass" ) ; } // Cache once and ignore subsequent caching // attempts if the entity is already stored if ( ! $ this -> has ( $ id ) ) { $ this -> instances [ $ id ] = $ entity ; } }
Add an entity to the cache.

@param mixed  $entity
@param string $id

@throws CacheException

@return void
Add an entity to the cache .