Skip to content

Implement first idea of the cache provider #488

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

Closed
wants to merge 4 commits into from

Conversation

Baachi
Copy link
Member

@Baachi Baachi commented Jan 18, 2016

Hey guys,

PSR6 has been released weeks ago and so we have a standard for caching. The feature has been wished thousand times so i started to work on it.
Currently this is only a proof of concept and i will finished it if we all fine with the idea.

My intention is currently: We provide multple strategies and the user can decide how he wants to cache the response.
Currently i wrote the stale-if-error strategy and the expire strategy, because i think these are the most common behaviours.

Please provide feedback 😄

@willdurand
Copy link
Member

👍

@willdurand
Copy link
Member

Also, Symfony 3.1 will have a Cache component.

@Baachi
Copy link
Member Author

Baachi commented Jan 19, 2016

Oh didn't know that, but wouldn't it be better to build against the psr/cache interface?

@drupol
Copy link

drupol commented Jan 21, 2016

I've implemented it in the Drupal module using custom code, without strategy. Code here: https://github.com/drupol/geocoder/blob/8.x-2.x/src/Plugin/Geocoder/Provider.php#L72

@toin0u
Copy link
Member

toin0u commented Jan 25, 2016

@Baachi Symfony added the PSR-6 implementation symfony/symfony#17408 :)

@Baachi
Copy link
Member Author

Baachi commented Jan 25, 2016

@toin0u Cool didn't know that 👍

@joelwurtz
Copy link

See #487 if it's only for HTTP request we (php-http) already provide a plugin for caching response with PSR6, this will maybe allow to reduce the maintenance on your side

@Baachi
Copy link
Member Author

Baachi commented Feb 1, 2016

@joelwurtz I know that httplug have a caching system but it uses the cache-control header and many providers doesn't set cache control header.
I would like to have a caching strategy which cover the following use cases:

  • The user hit the api limit, so load it from the cache so he have at least a result
  • The user wants to reduce the api limit, so use a cache

If this is possible through httplug, let me know.

@joelwurtz
Copy link

The user wants to reduce the api limit, so use a cache

The CachePlugin as an option to respect / ignore cache headers :respect_cache_headers, si if the request is within an acceptable method (GET or HEAD) and an acceptable status code (200, 203, 300, 301, 302, 404, 410) it is cached, even if the cache-control was set to no-cache.

The user hit the api limit, so load it from the cache so he have at least a result

In fact the CachePlugin has a protected method to determine if the response is cacheable or not (see https://github.com/php-http/plugins/blob/master/src/CachePlugin.php#L104). So for this use case you can extend the cache plugin and implementing the rule for api limit.

You also give me an idea about introducing a StaleCachePlugin, like caching response in another cache with a longer ttl, and if a following request / response is in failure, it reuse the cached one.

@Baachi
Copy link
Member Author

Baachi commented Feb 1, 2016

@joelwurtz This sounds indeed interesting and would also cover this use case.

In fact the CachePlugin has a protected method to determine if the response is cacheable or not (see https://github.com/php-http/plugins/blob/master/src/CachePlugin.php#L104). So for this use case you can extend the cache plugin and implementing the rule the api limit.

Yes this is right, but how would you detect if there is an error in this response? Geocoder already know this already and throw an exception if the provider hit the api limit or there is an other error.

@Baachi
Copy link
Member Author

Baachi commented Feb 1, 2016

@geocoder-php/geocoder ready for review 👍

@Baachi Baachi changed the title [PoC] Implement first idea of the cache provider Implement first idea of the cache provider Feb 1, 2016
@toin0u
Copy link
Member

toin0u commented Feb 9, 2016

@Baachi Good job! It looks good 👍 Just few missing phpdocs :)

@willdurand
Copy link
Member

👍

@willdurand
Copy link
Member

willdurand commented Jul 18, 2016

@Baachi any update on this PR?

@Baachi
Copy link
Member Author

Baachi commented Jul 24, 2016

Will try to finish up this PR this week.

@Nyholm
Copy link
Member

Nyholm commented Jul 25, 2016

FYI: One could use the CachePlugin to HTTPlug.

@Baachi
Copy link
Member Author

Baachi commented Nov 9, 2016

@willdurand do you still want this PR? If yes i will add the missing docs

@Nyholm
Copy link
Member

Nyholm commented Nov 9, 2016

Do we need this PR?
See this cookbook: https://github.com/geocoder-php/Geocoder/blob/master/docs/cookbook/cache.md

Doesn't that solve the cache problem for us?

@Baachi
Copy link
Member Author

Baachi commented Nov 9, 2016

@Nyholm this is the question, the only thing which isn't currently not covered is the stale-if-error strategy. But of course i can also open a PR to HTTPLug to cover this case.

@Nyholm
Copy link
Member

Nyholm commented Nov 9, 2016

I would vote for not merging this and add stale-if-error on the https://github.com/php-http/cache-plugin

@Baachi
Copy link
Member Author

Baachi commented Nov 9, 2016

@Nyholm Should i open an issue on the php-http/cache-plugin repo to discuss the implementation or are you okay with this implementation?

@Nyholm
Copy link
Member

Nyholm commented Nov 9, 2016

I think this implementation looks good. Since it is not too much code, I suggest to open a quick PR and we'll discuss it there. Do not spend too much time (or none) at the tests until you got some feedback.
There are some people watching that repo that are really skilled at HTTP cache. I guess they will have some input as well.

@atymic
Copy link
Member

atymic commented Jul 1, 2019

@Nyholm

Is this PR still needed?
It seems we have a CacheProvider in the package, as well as instructions on how to use the httplug cache?

@Baachi Baachi closed this Jul 1, 2019
@Baachi
Copy link
Member Author

Baachi commented Jul 1, 2019

I think this PR is not needed anymore :)
Sadly i didn't have time, to finish it 😢

@atymic
Copy link
Member

atymic commented Jul 1, 2019

Thanks @Baachi 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants