read<S> method

S read<S>(
  1. CacheModel<Serializable> model
)

Implementation

S read<S>(final CacheModel model) {
  if (model.value.isList) {
    throw AppException(
        message:
            "Invalid Cache for '${model.key}'. Item is an array, use readList() instead");
  }
  final cacheData = storage.read(model.key);
  if (cacheData == null) {
    return model.value.defaultObject();
  }
  _log(model.key,
      "Reading cache [${model.key}: ${cacheData.runtimeType}]: $cacheData");
  if (cacheData.runtimeType == List && (cacheData as List).isNotEmpty) {
    return model.value.fromJson((cacheData).first);
    // throw AppException(
    //     message: "Invalid Cache value for ${model.key}",
    //     description:
    //         "cache value for ${model.key} is list. Use readList instead");
  }
  return model.value.fromJson(cacheData);
}