Пример #1
0
    def __getitem__(self, entity_id: UUID) -> TVersionedEntity:
        """
        Returns entity with given ID.

        :param entity_id: ID of entity in the repository.
        :raises RepositoryKeyError: If the entity is not found.
        """
        if self._use_cache:
            try:
                # Get entity from the cache.
                entity: Optional[TVersionedEntity] = self._cache[entity_id]
            except KeyError:
                # Reconstitute the entity.
                entity = self.get_entity(entity_id)
                # Put entity in the cache.
                self._cache[entity_id] = entity
        else:
            entity = self.get_entity(entity_id)

        # Never created or already discarded?
        if entity is None:
            raise RepositoryKeyError(entity_id)

        # Return entity.
        assert entity is not None
        return entity
    def __getitem__(self, entity_id):
        """
        Returns entity with given ID.
        """
        if self._use_cache:
            try:
                # Get entity from the cache.
                entity = self._cache[entity_id]
            except KeyError:
                # Reconstitute the entity.
                entity = self.get_entity(entity_id)
                # Put entity in the cache.
                self._cache[entity_id] = entity
        else:
            entity = self.get_entity(entity_id)

        # Never created or already discarded?
        if entity is None:
            raise RepositoryKeyError(entity_id)

        # Return entity.
        return entity
    def __getitem__(self, entity_id):
        """
        Returns entity with given ID.
        """
        # # Get entity from the cache.
        # if self._use_cache:
        #     try:
        #         return self._cache[entity_id]
        #     except KeyError:
        #         pass

        # Reconstitute the entity.
        entity = self.get_entity(entity_id)

        # Never created or already discarded?
        if entity is None:
            raise RepositoryKeyError(entity_id)

        # # Put entity in the cache.
        # if self._use_cache:
        #     self.add_cache(entity_id, entity)

        # Return entity.
        return entity