Response time is 18 seconds but storing to cache time is 3 minutes. Why is that? I used sqflite plugin to store data. This is my function calling server with an insert to cache

storeWoDescription(String url,String token) async {
  final response = await http.get(
    '${url}/v1.0/WoDescription',
    headers: {'Authorization': 'Bearer ${token}'},);
  final jsonResponse = json.decode(response.body);
  WoDescription model = WoDescription.fromJson(jsonResponse);
  int length = model.data.length;

  for(int i=0; i<length; i++) {
    var data = DataWoDescription(
      i: model.data[i].i,
      d: model.data[i].d,
      e: model.data[i].e,
      w: model.data[i].w,
      a: model.data[i].a,
      r: model.data[i].r,
      t: model.data[i].t,
      du: model.data[i].du,
      s: model.data[i].s,
      ra: model.data[i].ra,
      cul: model.data[i].cul,
    );
    await HelperDefCatMaster().insertWoDescription(data);
  }
}

after click button calling like this:

   await storeWoDescription(_url,tokens);

HelperDefCatMaster this is my database provider. I created multiple tables in one database. and before insert, I deleted the database and after that I inserted.

class HelperDefCatMaster {
  static final HelperDefCatMaster _instance = HelperDefCatMaster.internal();

  factory HelperDefCatMaster() => _instance;
  static Database _db;

  Future<Database> get db1 async {
    if (_db != null) return _db;
    _db = await initDb();
    return _db;
  }

  HelperDefCatMaster.internal();

  initDb() async {
    io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, "HelperDefCatMasterDB.db");
    var theDb = await openDatabase(path, version: 1, onCreate: _onCreate);
    return theDb;
  }

  void _onCreate(Database db, int version) async {
    await db.execute(
        """CREATE TABLE WoDescriptionTable(i INTEGER, d STRING, e INTEGER, w STRING, a INTEGER, r INTEGER, t INTEGER, du DOUBLE, s INTEGER, ra INTEGER, cul INTEGER)""");
  }

  Future<void> insertWoDescription(DataWoDescription assetregister) async {
    var db = await db1;
    await db.insert(
      'WoDescriptionTable',
      assetregister.toMap()
     // conflictAlgorithm: ConflictAlgorithm.replace,
    );
  }


  Future<void> deleteWoDescription() async {
    var db = await db1;
    await db.delete('WoDescriptionTable');
  }



  Future<List<DataWoDescription>> displayWoDescription() async {
    var db = await db1;
    final List<Map<String, dynamic>> maps = await db.query('WoDescriptionTable');

    return List.generate(maps.length, (i) {
      return DataWoDescription(
        i: maps[i]['i'],
        d: '${maps[i]['d']}',
        e: maps[i]['e'],
        w: '${maps[i]['w']}',
        a: maps[i]['a'],
        r: maps[i]['r'],
        t: maps[i]['t'],
        du: maps[i]['du'],
        s: maps[i]['s'],
        ra: maps[i]['ra'],
        cul: maps[i]['cul'],
      );
    });
  }
}

0 Answers