<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_representation(self, instance):
 """Modified to_representation method. Optionally may cache objects. Arguments: instance: A model instance or data object. Returns: Instance ID if the serializer is meant to represent its ID. Otherwise, a tagged data dict representation. """

        if self.id_only():
            return instance.pk

        pk = getattr(instance, 'pk', None)
        if not settings.ENABLE_SERIALIZER_OBJECT_CACHE or pk is None:
            return self._to_representation(instance)
        else:
            if pk not in self.obj_cache:
                self.obj_cache[pk] = self._to_representation(instance)
            return self.obj_cache[pk]