0

Trying to refactor a feed plugin to fallback on cache if source is unavailable (ex: for maintenance).

Started using fetch_feed($url); which affords more flexibility in terms of cache. But unsure of how to structure the fallback.

0

Sounds like you are looking at it from a very low layer POV. fetch_feed provides caching so you will not need to wait for a response on possibly every page load. Therefor, as long as there is a cache you are unlikely to even want a message to be sent and obviously you are not handling any actual result. It is unlikely that you will want to hurt your server with a faster refresh rate just to be able to properly detect the conditions on the other side.

What you should do is to handle the situation of not getting a reply, which is probably equal to empty feed, to supply the defaults you want.

  • Yes, I was thinking something like so: if(is_wp_error($rss)){ $rss = get_transient('my_rss_feed'); } – MediaFormat Feb 2 '18 at 4:35
  • So I've read that fetch_feed is cached 12hrs by default, But what if I want the cache to expire every 30mins, but have a fallback that lasts 12hrs. Is it possible to have 2 caches? If I set my own transient, will the default cache still work? – MediaFormat Feb 2 '18 at 4:50
  • 1
    I am not sure about the minimal interval you can set for the fetch_feed caching, but I guess it is possible to set it to 30 min. Than at you higher level you can set a transient with whatever is your default and set it to expire after 12 hours. – Mark Kaplun Feb 2 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.