toString method
A string representation of this object.
Some classes have a default textual representation,
often paired with a static parse
function (like int.parse).
These classes will provide the textual representation as
their string representation.
Other classes have no meaningful textual representation
that a program will care about.
Such classes will typically override toString
to provide
useful information when inspecting the object,
mainly for debugging or logging.
Implementation
@override
String toString() {
List<String> values;
if (hasDirective(CacheControlDirective.noCache)) {
values = <String>[
'no-cache',
if (hasDirective(CacheControlDirective.noStore)) 'no-store',
if (hasDirective(CacheControlDirective.noTransform)) 'no-transform',
'max-age=0',
];
} else {
values = <String>[];
if (hasDirective(CacheControlDirective.private)) {
values.add('private');
} else if (hasDirective(CacheControlDirective.public)) {
values.add('public');
}
if (hasDirective(CacheControlDirective.noStore)) {
values.add('no-store');
}
if (hasDirective(CacheControlDirective.noTransform)) {
values.add('no-transform');
}
if (hasDirective(CacheControlDirective.mustRevalidate)) {
values.add('must-revalidate');
}
var maxAgeSecs = maxAge.inSeconds;
values.add('max-age=$maxAgeSecs');
var staleAgeSecs = staleAge.inSeconds;
if (staleAgeSecs < maxAgeSecs) {
staleAgeSecs = maxAgeSecs;
}
var staleIfErrorAgeSecs = staleIfErrorAge.inSeconds;
if (staleIfErrorAgeSecs < maxAgeSecs) {
staleIfErrorAgeSecs = maxAgeSecs;
}
if (hasDirective(CacheControlDirective.staleWhileRevalidate)) {
values.add('stale-while-revalidate=$staleAgeSecs');
}
if (hasDirective(CacheControlDirective.staleIfError)) {
values.add('stale-if-error=$staleIfErrorAgeSecs');
}
}
return values.join(', ');
}