removeCachedEntity<O> method

O? removeCachedEntity<O>(
  1. dynamic id, {
  2. Type? type,
  3. bool instantiate = true,
})

Removes an entity of type with id of this cache.

Implementation

O? removeCachedEntity<O>(dynamic id, {Type? type, bool instantiate = true}) {
  if (id == null) return null;
  type ??= O;
  var typeEntities = _entities?[type];
  var entity = typeEntities?.remove(id) as O?;

  var typeEntitiesInstantiators = _entitiesInstantiators?[type];
  var entityInstantiator = typeEntitiesInstantiators?.remove(id);

  if (entityInstantiator != null && instantiate) {
    entity ??= entityInstantiator() as O?;
  }

  return entity;
}