parse static method
dartvel.web.server.http. A value of the wrong kind is the default
rather than an error: the manifest is read by a server in production,
where refusing to start over a cache setting is worse than ignoring it.
Implementation
static DVAssetHttpPolicy parse(Object? section) {
final Map<Object?, Object?> m = section is Map ? section : const <Object?, Object?>{};
int? seconds(Object? v) => v is num && v >= 0 ? v.toInt() : null;
final Object? immutable = m['immutable'];
final Object? documents = m['documents'];
final Object? memory = m['memoryCacheMB'];
return DVAssetHttpPolicy(
maxAge: seconds(m['maxAge']),
sMaxAge: seconds(m['sMaxAge']),
staleWhileRevalidate: seconds(m['staleWhileRevalidate']),
immutable: immutable is List
? <String>[for (final Object? g in immutable) if (g is String && g.isNotEmpty) g]
: const <String>[],
documents: documents is String && documents.trim().isNotEmpty ? documents.trim() : 'no-cache',
memoryCacheBytes: memory is num && memory >= 0
? (memory * 1024 * 1024).round()
: 16 * 1024 * 1024,
diskCache: m['diskCache'] is bool ? m['diskCache']! as bool : true,
);
}