Features
store cached varibles
Getting started
suppose cached data types
class c0{
String id;
int time;
c0(this.id,this.time);
c0.fromMap(Map<String,dynamic>m):id=m["id"],time=int.parse("${m["time"]}");
toMap()=>{"id":id,"time":time};
}
class c1{
String id;
String name;
c1(this.id,this.name);
c1.fromMap(Map<String,dynamic>m):id=m["id"],name=m["name"];
toMap()=>{"id":id,"name":name};
}
final cache=cacheManager({c0:[(c0 x)=>x.toMap(),c0.fromMap]});
await Future.delayed(Duration(milliseconds: 500));
cache.check();
expect(cache.get<c0>("id0"), null);
cache.addOrUpdate<c0>(c0("id0", 1));
cache.check();
expect(cache.get<c0>("id0").toString(), c0("id0", 1));
final cache=cacheManager({
c0:[(c0 x)=>x.toMap(),c0.fromMap],
c1:[(c1 x)=>x.toMap(),c1.fromMap],
});
await Future.delayed(Duration(milliseconds: 500));
cache.check();
// expect(cache.get<c0>("id0"), null);
cache.addOrUpdate<c0>(c0("id0", 1));
cache.addOrUpdate<c1>(c1("id01", "a instance"));
cache.check();
cache.update(c1, "id01", {"name":"an instance"});
print(cache.get<c1>("id01")?.toMap());
cache.check();