class RequestCacheControl {

    @Override
    public String toString() {
        StringBuilder buffer = new StringBuilder();

        if (_noCache) {
            appendDirective(buffer, "no-cache");
        }

        if (_noStore) {
            appendDirective(buffer, "no-store");
        }

        if (_maxAge >= 0) {
            appendDirective(buffer, "max-age", _maxAge);
        }

        if (_maxStale == Integer.MAX_VALUE) {
            appendDirective(buffer, "max-stale");
        } else if (_maxStale >= 0) {
            appendDirective(buffer, "max-stale", _maxStale);
        }

        if (_minFresh >= 0) {
            appendDirective(buffer, "min-fresh", _minFresh);
        }

        if (_noTransform) {
            appendDirective(buffer, "no-transform");
        }

        if (_onlyIfCached) {
            appendDirective(buffer, "only-if-cached");
        }

        if (_cacheExtension != null) {
            for (Map.Entry<String, Optional<String>> entry : _cacheExtension.entrySet()) {
                appendDirective(buffer, entry.getKey(), entry.getValue());
            }
        }

        return buffer.toString();
    }

}