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

[ENH] Allow caching failed requests #741

Open
mikkorantalainen opened this issue Aug 26, 2022 · 1 comment
Open

[ENH] Allow caching failed requests #741

mikkorantalainen opened this issue Aug 26, 2022 · 1 comment
Assignees

Comments

@mikkorantalainen
Copy link

Whenever end users are allowed to submit feed URLs to fetch, there's always a possibility of typo in the host or path and in case the response for the feed is failed connection or some resource that cannot be turned into feed, it would be nice to be able to cache the failed response.

I think this should be opt-in because it would change the default behavior of the library otherwise.

Possible solution

Add new API point:

class SimplePie
{
	# ...
	/**
	 * @param int $seconds The cache expiry time for cached failed requests. Use 0 to disable caching of failed requests.
	 */
	public function set_cache_remember_failure($seconds=60*15)
	{
		# ...
	}
	# ...

(and obviously implement the code that checks if the URL has failed in the past and if failed duration hasn't yet passed, return failed response to the caller instead of waiting for timeout).

This would allow pages that want to embed RSS feeds to keep high performance even if the remote host goes down because only one request per failed cache expiry period would stall for trying to connect the remote host that's actually down.

@mikkorantalainen
Copy link
Author

Nice to have: if force_cache_fallback(true) has been set, allow marking existing cache with the latest known good feed as failed so that it will not be retried until the failed cache expiry time has elapsed but instead the last known good copy is returned immediately.

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

No branches or pull requests

2 participants