CachePolicy.fromJson constructor

CachePolicy.fromJson(
  1. Object? j
)

Implementation

factory CachePolicy.fromJson(Object? j) {
  final json = j as Map<String, Object?>;
  return CachePolicy(
    cacheBypassRequestHeaderNames:
        switch (json['cacheBypassRequestHeaderNames']) {
          null => [],
          List<Object?> $1 => [for (final i in $1) decodeString(i)],
          _ => throw const FormatException(
            '"cacheBypassRequestHeaderNames" is not a list',
          ),
        },
    cacheKeyPolicy: switch (json['cacheKeyPolicy']) {
      null => null,
      Object $1 => CachePolicyCacheKeyPolicy.fromJson($1),
    },
    cacheMode: switch (json['cacheMode']) {
      null => null,
      Object $1 => decodeString($1),
    },
    clientTtl: switch (json['clientTtl']) {
      null => null,
      Object $1 => Duration.fromJson($1),
    },
    defaultTtl: switch (json['defaultTtl']) {
      null => null,
      Object $1 => Duration.fromJson($1),
    },
    maxTtl: switch (json['maxTtl']) {
      null => null,
      Object $1 => Duration.fromJson($1),
    },
    negativeCaching: switch (json['negativeCaching']) {
      null => null,
      Object $1 => decodeBool($1),
    },
    negativeCachingPolicy: switch (json['negativeCachingPolicy']) {
      null => [],
      List<Object?> $1 => [
        for (final i in $1) CachePolicyNegativeCachingPolicy.fromJson(i),
      ],
      _ => throw const FormatException(
        '"negativeCachingPolicy" is not a list',
      ),
    },
    requestCoalescing: switch (json['requestCoalescing']) {
      null => null,
      Object $1 => decodeBool($1),
    },
    serveWhileStale: switch (json['serveWhileStale']) {
      null => null,
      Object $1 => Duration.fromJson($1),
    },
  );
}