@@ -72,7 +72,12 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
7272
7373 if (!$ skipCache ) {
7474 try {
75- $ this ->provider ->import (json_decode ($ this ->cache ->get ($ remote ) ?? '' , true , 8 , JSON_THROW_ON_ERROR ) ?? []);
75+ $ cached = $ this ->cache ->get ($ remote );
76+ if ($ cached === false ) {
77+ throw new OCMProviderException ('Previous discovery failed. ' );
78+ }
79+
80+ $ this ->provider ->import (json_decode ($ cached ?? '' , true , 8 , JSON_THROW_ON_ERROR ) ?? []);
7681 if ($ this ->supportedAPIVersion ($ this ->provider ->getApiVersion ())) {
7782 return $ this ->provider ; // if cache looks valid, we use it
7883 }
@@ -99,8 +104,10 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
99104 $ this ->cache ->set ($ remote , $ body , 60 * 60 * 24 );
100105 }
101106 } catch (JsonException |OCMProviderException $ e ) {
107+ $ this ->cache ->set ($ remote , false , 5 * 60 );
102108 throw new OCMProviderException ('data returned by remote seems invalid - ' . ($ body ?? '' ));
103109 } catch (\Exception $ e ) {
110+ $ this ->cache ->set ($ remote , false , 5 * 60 );
104111 $ this ->logger ->warning ('error while discovering ocm provider ' , [
105112 'exception ' => $ e ,
106113 'remote ' => $ remote
@@ -109,6 +116,7 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
109116 }
110117
111118 if (!$ this ->supportedAPIVersion ($ this ->provider ->getApiVersion ())) {
119+ $ this ->cache ->set ($ remote , false , 5 * 60 );
112120 throw new OCMProviderException ('API version not supported ' );
113121 }
114122
0 commit comments