getCachedEntitiesByIDs<O> method

  1. @override
Map<dynamic, Object>? getCachedEntitiesByIDs<O>(
  1. List ids, {
  2. Type? type,
  3. bool removeCachedIDs = false,
})
override

Returns the cached entities of type with ids.

  • If removeCachedIDs is true it will remove the matching cached entities from ids.

Implementation

@override
Map<dynamic, Object>? getCachedEntitiesByIDs<O>(List<dynamic> ids,
    {Type? type, bool removeCachedIDs = false}) {
  type ??= O;

  var cachedEntities = _entities[type];
  if (cachedEntities == null) return null;

  var cachedEntitiesByIDs = Map<dynamic, Object>.fromEntries(ids.map((id) {
    var entity = cachedEntities[id];
    return entity != null ? MapEntry(id, entity) : null;
  }).whereNotNull());

  if (cachedEntitiesByIDs.isEmpty) return null;

  if (removeCachedIDs) {
    ids.removeWhere((id) => cachedEntitiesByIDs.containsKey(id));
  }

  return cachedEntitiesByIDs;
}