@@ -38,6 +38,13 @@ final class Client
3838 */
3939 const CACHE_MODE_ALL = 3 ;
4040
41+ /**
42+ * Flag to refresh cache on ALL requests
43+ *
44+ * @const int
45+ */
46+ const CACHE_MODE_REFRESH = 4 ;
47+
4148 /**
4249 * Base url of the API server
4350 *
@@ -129,7 +136,11 @@ public function __construct(
129136 Util::throwIfNotType (['string ' => [$ accessToken , $ refreshToken ]], true , true );
130137 Util::ensure (
131138 true ,
132- in_array ($ cacheMode , [self ::CACHE_MODE_NONE , self ::CACHE_MODE_GET , self ::CACHE_MODE_TOKEN , self ::CACHE_MODE_ALL ], true ),
139+ in_array (
140+ $ cacheMode ,
141+ [self ::CACHE_MODE_NONE , self ::CACHE_MODE_GET , self ::CACHE_MODE_TOKEN , self ::CACHE_MODE_ALL , self ::CACHE_MODE_REFRESH ],
142+ true
143+ ),
133144 '\InvalidArgumentException ' ,
134145 ['$cacheMode must be a valid cache mode constant ' ]
135146 );
@@ -304,7 +315,7 @@ public function end($handle)
304315 $ response = $ this ->_adapter ->end ($ this ->_adapter ->start ($ request ));
305316 }
306317
307- if ($ this ->_cacheMode & self ::CACHE_MODE_GET && $ request ->getMethod () === 'GET ' ) {
318+ if (( $ this ->_cacheMode === self :: CACHE_MODE_REFRESH || $ this -> _cacheMode & self ::CACHE_MODE_GET ) && $ request ->getMethod () === 'GET ' ) {
308319 $ this ->_cache ->set ($ request , $ response );
309320 }
310321
@@ -363,7 +374,7 @@ private function _refreshAccessToken()
363374
364375 list ($ this ->_accessToken , $ this ->_refreshToken , $ expires ) = Authentication::parseTokenResponse ($ response );
365376
366- if ($ this ->_cacheMode & self ::CACHE_MODE_TOKEN ) {
377+ if ($ this ->_cache === self :: CACHE_MODE_REFRESH || $ this -> _cacheMode & self ::CACHE_MODE_TOKEN ) {
367378 $ this ->_cache ->set ($ request , $ response , $ expires );
368379 }
369380 }
0 commit comments