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

[question] how to define time how long should the cache live? #117

Open
str opened this issue Sep 14, 2019 · 1 comment
Open

[question] how to define time how long should the cache live? #117

str opened this issue Sep 14, 2019 · 1 comment

Comments

@str
Copy link

str commented Sep 14, 2019

Hi!

It looks like my cache lasts for a very short time. This is how I define my cache middleware:

        $stack = HandlerStack::create();
        $stack->push(
            new CacheMiddleware(
                new PrivateCacheStrategy(
                    new FlysystemStorage(
                        new Local('./tmp/cache/guzzle/')
                    )
                )
            ),
            'cache'
        );
        $client = new Client([
            'handler'         => $stack,
            'allow_redirects' => false,
            'referer'         => true,
            'track_redirects' => true,
        ]);

how can I define how long my cache should last? Like in days?

@marcus-at-localhost
Copy link

@str You can set time like this.

new PrivateCacheStrategy(
	new FlysystemStorage(
		new Local('./tmp/cache/guzzle/')
    ), 60 // <= 60 seconds
)

Although my experience was, if the server doesn't return proper caching headers (for how long content is cache-able), then nothing really happens (beside a file being written, the network access happens anyway).

You can force caching with \GreedyCacheStrategy and then the caching time setting is honored. The middleware is also setting a Http Header, warning you:

'Cached although the response headers indicate not to do it!',

Hope that helps someone, please correct me if I'm wrong.

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

2 participants