Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Baachi wants to merge4 commits intogeocoder-php:masterfromBaachi:feature/cache

Conversation

@Baachi
Copy link
Member

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 decidehow he wants to cache the response.
Currently i wrote thestale-if-error strategy and theexpire 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
MemberAuthor

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

@drupol
Copy link

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

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

@Baachi
Copy link
MemberAuthor

@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
MemberAuthor

@joelwurtz I know that httplug have a caching system but it uses thecache-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 tono-cache.

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

In fact theCachePlugin has a protected method to determine if the response is cacheable or not (seehttps://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
MemberAuthor

@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 (seehttps://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
MemberAuthor

@geocoder-php/geocoder ready for review 👍

@BaachiBaachi changed the title[PoC] Implement first idea of the cache providerImplement first idea of the cache providerFeb 1, 2016
@toin0u
Copy link
Member

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

@willdurand
Copy link
Member

👍

@willdurand
Copy link
Member

willdurand commentedJul 18, 2016
edited
Loading

@Baachi any update on this PR?

@Baachi
Copy link
MemberAuthor

Will try to finish up this PR this week.

@Nyholm
Copy link
Member

FYI: One could use the CachePlugin to HTTPlug.

@Baachi
Copy link
MemberAuthor

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

@Nyholm
Copy link
Member

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
MemberAuthor

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

@Nyholm
Copy link
Member

I would vote for not merging this and addstale-if-error on thehttps://github.com/php-http/cache-plugin

@Baachi
Copy link
MemberAuthor

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

@Nyholm
Copy link
Member

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.

@NyholmNyholm mentioned this pull requestDec 22, 2016
@atymic
Copy link
Member

@Nyholm

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

@BaachiBaachi closed thisJul 1, 2019
@Baachi
Copy link
MemberAuthor

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

atymic reacted with thumbs up emoji

@atymic
Copy link
Member

Thanks@Baachi 😄

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@Baachi@willdurand@drupol@toin0u@joelwurtz@Nyholm@atymic

[8]ページ先頭

©2009-2025 Movatter.jp