Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interface for etag caching #164

Open
sspat opened this issue Apr 26, 2021 · 0 comments
Open

Add interface for etag caching #164

sspat opened this issue Apr 26, 2021 · 0 comments

Comments

@sspat
Copy link
Contributor

sspat commented Apr 26, 2021

If request handler implements interface, is serving a GET request and has a If-None-Match header, the interface method eTag should be called before calling the request handler main method.

If the returned etag matches the etag from the request header "If-None-Match" - return 304 with empty body, if not - execute the request handler main method as usual.

Also, if request handler implements interface and is serving a GET request, the interface methods revalidate, cacheable, maxAge should be called before returning the response, setting the Cache-Control response header value based on the methods return values.

https://web.dev/http-cache/

Update tests, docs

<?php

declare(strict_types=1);

namespace OnMoon\OpenApiServerBundle\Interfaces;

use OnMoon\OpenApiServerBundle\Interfaces\Dto;

interface HTTPCached
{
    public const CACHE_NO_STORE = 'no-store';
    public const CACHE_NO_CACHE = 'no-cache';

    public const CACHEABLE_PUBLIC = 'private';
    public const CACHEABLE_PRIVATE = 'public';

    public function eTag(): string;

    /** @psalm-return HTTPCached::CACHE_NO_*|null */
    public function revalidate(): ?string;

    /** @psalm-return HTTPCached::CACHEABLE_* */
    public function cacheable(): string;

    public function maxAge(): int;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant