@@ -32,8 +32,7 @@ import com.adamratzman.spotify.models.serialization.getSavedTrackConverter
32
32
import com.adamratzman.spotify.models.serialization.toObject
33
33
import com.beust.klaxon.Klaxon
34
34
import java.util.concurrent.Executors
35
- import java.util.concurrent.ScheduledFuture
36
- import java.util.concurrent.TimeUnit
35
+ import java.util.concurrent.ScheduledExecutorService
37
36
38
37
internal val base = " https://api.spotify.com/v1"
39
38
@@ -67,20 +66,16 @@ abstract class SpotifyAPI internal constructor(
67
66
var retryWhenRateLimited : Boolean ,
68
67
enableLogger : Boolean
69
68
) {
70
- private var refreshFuture: ScheduledFuture <* >? = null
71
-
72
69
var useCache = useCache
73
70
set(value) {
74
- if (! useCache && value) refreshFuture = startCacheRefreshRunnable()
75
- else if (useCache && ! value) refreshFuture?.cancel(false )
76
-
77
71
if (! value) clearCache()
78
72
79
73
field = value
80
74
}
81
75
82
- internal var expireTime = System .currentTimeMillis() + token.expiresIn * 1000
83
- internal val executor = Executors .newScheduledThreadPool(0 )
76
+ val expireTime: Long get() = System .currentTimeMillis() + token.expiresIn * 1000
77
+
78
+ val executor: ScheduledExecutorService = Executors .newScheduledThreadPool(0 )
84
79
85
80
abstract val search: SearchAPI
86
81
abstract val albums: AlbumAPI
@@ -91,9 +86,9 @@ abstract class SpotifyAPI internal constructor(
91
86
abstract val tracks: TracksAPI
92
87
abstract val following: FollowingAPI
93
88
94
- internal val logger = SpotifyLogger (enableLogger)
89
+ val logger = SpotifyLogger (enableLogger)
95
90
96
- abstract val klaxon: Klaxon
91
+ internal abstract val klaxon: Klaxon
97
92
98
93
/* *
99
94
* If the method used to create the [token] supports token refresh and
@@ -119,12 +114,6 @@ abstract class SpotifyAPI internal constructor(
119
114
*/
120
115
abstract fun getApiBuilderDsl (): SpotifyApiBuilderDsl
121
116
122
- init {
123
- if (useCache) refreshFuture = startCacheRefreshRunnable()
124
- }
125
-
126
- private fun startCacheRefreshRunnable () = executor.scheduleAtFixedRate(::clearCache, 10 , 10 , TimeUnit .MINUTES )
127
-
128
117
internal fun clearAllCaches (vararg endpoints : SpotifyEndpoint ) {
129
118
endpoints.forEach { it.cache.clear() }
130
119
}
@@ -194,7 +183,6 @@ class SpotifyAppAPI internal constructor(
194
183
val currentToken = this .token
195
184
196
185
token = getCredentialedToken(clientId, clientSecret, this )
197
- expireTime = System .currentTimeMillis() + token.expiresIn * 1000
198
186
199
187
return currentToken
200
188
}
@@ -304,7 +292,7 @@ class SpotifyClientAPI internal constructor(
304
292
* Stop all automatic functions like refreshToken or clearCache and shut down the scheduled
305
293
* executor
306
294
* */
307
- fun cancelAutomatics () = executor.shutdown()
295
+ fun shutdown () = executor.shutdown()
308
296
309
297
override fun refreshToken (): Token {
310
298
val currentToken = this .token
0 commit comments