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;
        }
    }