get<T> method
Returns data from Hive based on key
cacheInvalidation
is the optional parameter.
It gets executed after certain invalidationInterval which is defined
at policy
cacheInvalidation
runs after returning the cached data.
It will return the updated data the next time you will hit.
Implementation
Future<T?> get<T>(String key, {HasDataChanged<T>? cacheInvalidation}) async {
final resolver = _getResolver<T>();
final item = _box.get(_generateHiveKey(key));
if (item != null) {
if (item.expireOn.compareTo(DateTime.now()) > -1 && item.key == key) {
_invalidateCache<T>(item, cacheInvalidation);
return resolver.cacheDataToType(item.data);
}
delete(key);
}
return null;
}