@@ -23,6 +23,7 @@ class SpotifyApiBuilder(
23
23
var tokenString : String? = null ,
24
24
var token : Token ? = null ,
25
25
var useCache : Boolean = true ,
26
+ var cacheLimit : Int? = 200 ,
26
27
var automaticRefresh : Boolean = true ,
27
28
var retryWhenRateLimited : Boolean = false ,
28
29
var enableLogger : Boolean = false
@@ -69,6 +70,11 @@ class SpotifyApiBuilder(
69
70
*/
70
71
fun useCache (useCache : Boolean ) = apply { this .useCache = useCache }
71
72
73
+ /* *
74
+ * Set the maximum allowed amount of cached requests at one time. Null means no limit
75
+ */
76
+ fun cacheLimit (cacheLimit : Int? ) = apply { this .cacheLimit = cacheLimit }
77
+
72
78
/* *
73
79
* Set the application [redirect uri](https://developer.spotify.com/documentation/general/guides/authorization-guide/)
74
80
*/
@@ -200,6 +206,7 @@ class SpotifyUserAuthorizationBuilder(
200
206
* @property authentication A holder for authentication methods. At least one needs to be provided in order to create
201
207
* a **client** api
202
208
* @property useCache Set whether to cache requests. Default: true
209
+ * @property cacheLimit The maximum amount of cached requests allowed at one time. Null means no limit
203
210
* @property automaticRefresh Enable or disable automatic refresh of the Spotify access token
204
211
* @property retryWhenRateLimited Set whether to block the current thread and wait until the API can retry the request
205
212
* @property enableLogger Set whether to enable to the exception logger
@@ -208,6 +215,7 @@ class SpotifyApiBuilderDsl {
208
215
private var credentials: SpotifyCredentials = SpotifyCredentials (null , null , null )
209
216
private var authentication = SpotifyUserAuthorizationBuilder ()
210
217
var useCache: Boolean = true
218
+ var cacheLimit: Int? = 200
211
219
var automaticRefresh: Boolean = true
212
220
var retryWhenRateLimited: Boolean = false
213
221
var enableLogger: Boolean = false
@@ -261,7 +269,7 @@ class SpotifyApiBuilderDsl {
261
269
return when {
262
270
authentication.token != null -> {
263
271
SpotifyAppAPI (clientId ? : " not-set" , clientSecret
264
- ? : " not-set" , authentication.token!! , useCache, false , retryWhenRateLimited, enableLogger)
272
+ ? : " not-set" , authentication.token!! , useCache, cacheLimit, false , retryWhenRateLimited, enableLogger)
265
273
}
266
274
authentication.tokenString != null -> {
267
275
SpotifyAppAPI (
@@ -272,6 +280,7 @@ class SpotifyApiBuilderDsl {
272
280
60000 , null , null
273
281
),
274
282
useCache,
283
+ cacheLimit,
275
284
automaticRefresh,
276
285
retryWhenRateLimited,
277
286
enableLogger
@@ -280,7 +289,7 @@ class SpotifyApiBuilderDsl {
280
289
else -> try {
281
290
if (clientId == null || clientSecret == null ) throw IllegalArgumentException (" Illegal credentials provided" )
282
291
val token = getCredentialedToken(clientId, clientSecret, null )
283
- SpotifyAppAPI (clientId, clientSecret, token, useCache, automaticRefresh, retryWhenRateLimited, enableLogger)
292
+ SpotifyAppAPI (clientId, clientSecret, token, useCache, cacheLimit, automaticRefresh, retryWhenRateLimited, enableLogger)
284
293
} catch (e: Exception ) {
285
294
throw SpotifyException (" Invalid credentials provided in the login process" , e)
286
295
}
@@ -337,7 +346,8 @@ class SpotifyApiBuilderDsl {
337
346
val response = executeTokenRequest(HttpConnection (
338
347
url = " https://accounts.spotify.com/api/token" ,
339
348
method = HttpRequestMethod .POST ,
340
- body = " grant_type=authorization_code&code=$authorizationCode &redirect_uri=$redirectUri " ,
349
+ bodyMap = null ,
350
+ bodyString = " grant_type=authorization_code&code=$authorizationCode &redirect_uri=$redirectUri " ,
341
351
contentType = " application/x-www-form-urlencoded" ,
342
352
api = null
343
353
), clientId, clientSecret)
@@ -349,6 +359,7 @@ class SpotifyApiBuilderDsl {
349
359
automaticRefresh,
350
360
redirectUri ? : throw IllegalArgumentException (),
351
361
useCache,
362
+ cacheLimit,
352
363
retryWhenRateLimited,
353
364
enableLogger
354
365
)
@@ -362,6 +373,7 @@ class SpotifyApiBuilderDsl {
362
373
automaticRefresh,
363
374
redirectUri ? : " not-set" ,
364
375
useCache,
376
+ cacheLimit,
365
377
retryWhenRateLimited,
366
378
enableLogger
367
379
)
@@ -378,6 +390,7 @@ class SpotifyApiBuilderDsl {
378
390
false ,
379
391
redirectUri ? : " not-set" ,
380
392
useCache,
393
+ cacheLimit,
381
394
retryWhenRateLimited,
382
395
enableLogger
383
396
)
0 commit comments