@@ -33,19 +33,19 @@ abstract class SpotifyEndpoint(val api: SpotifyAPI) {
33
33
}
34
34
35
35
internal fun delete (
36
- url : String ,
37
- body : String? = null,
38
- contentType : String? = null
36
+ url : String ,
37
+ body : String? = null,
38
+ contentType : String? = null
39
39
): String {
40
40
return execute(url, body, HttpRequestMethod .DELETE , contentType = contentType)
41
41
}
42
42
43
43
private fun execute (
44
- url : String ,
45
- body : String? = null,
46
- method : HttpRequestMethod = HttpRequestMethod .GET ,
47
- retry202 : Boolean = true,
48
- contentType : String? = null
44
+ url : String ,
45
+ body : String? = null,
46
+ method : HttpRequestMethod = HttpRequestMethod .GET ,
47
+ retry202 : Boolean = true,
48
+ contentType : String? = null
49
49
): String {
50
50
if (api is SpotifyAppAPI && System .currentTimeMillis() >= api.expireTime) api.refreshToken()
51
51
@@ -73,10 +73,10 @@ abstract class SpotifyEndpoint(val api: SpotifyAPI) {
73
73
}
74
74
75
75
private fun handleResponse (
76
- document : HttpResponse ,
77
- cacheState : CacheState ? ,
78
- spotifyRequest : SpotifyRequest ,
79
- retry202 : Boolean
76
+ document : HttpResponse ,
77
+ cacheState : CacheState ? ,
78
+ spotifyRequest : SpotifyRequest ,
79
+ retry202 : Boolean
80
80
): String? {
81
81
val statusCode = document.responseCode
82
82
@@ -109,10 +109,10 @@ abstract class SpotifyEndpoint(val api: SpotifyAPI) {
109
109
}
110
110
111
111
private fun createConnection (
112
- url : String ,
113
- body : String? = null,
114
- method : HttpRequestMethod = HttpRequestMethod .GET ,
115
- contentType : String? = null
112
+ url : String ,
113
+ body : String? = null,
114
+ method : HttpRequestMethod = HttpRequestMethod .GET ,
115
+ contentType : String? = null
116
116
) = HttpConnection (
117
117
url,
118
118
method,
@@ -169,27 +169,26 @@ class SpotifyCache {
169
169
cachedRequests.entries.removeIf { ! it.value.isStillValid() }
170
170
171
171
val cacheLimit = request.api.cacheLimit
172
- val cacheUse = request.api.endpoints.sumBy { it.cache. cachedRequests.size }
172
+ val cacheUse = cachedRequests.size
173
173
174
174
if (cacheLimit != null && cacheUse > cacheLimit) {
175
175
val amountRemoveFromEach = ceil((cacheUse - cacheLimit).toDouble() / request.api.endpoints.size).toInt()
176
176
177
- request.api.endpoints.forEach { endpoint ->
178
- val entries = endpoint.cache.cachedRequests.entries
179
- val toRemove = entries.sortedBy { it.value.expireBy }.take(amountRemoveFromEach)
177
+ val entries = cachedRequests.entries
180
178
181
- if (toRemove.isNotEmpty()) entries.removeAll(toRemove)
182
- }
179
+ val toRemove = entries.sortedBy { it.value.expireBy }.take(amountRemoveFromEach)
180
+
181
+ if (toRemove.isNotEmpty()) entries.removeAll(toRemove)
183
182
}
184
183
}
185
184
}
186
185
}
187
186
188
187
data class SpotifyRequest (
189
- val url : String ,
190
- val method : HttpRequestMethod ,
191
- val body : String? ,
192
- val api : SpotifyAPI
188
+ val url : String ,
189
+ val method : HttpRequestMethod ,
190
+ val body : String? ,
191
+ val api : SpotifyAPI
193
192
)
194
193
195
194
data class CacheState (val data : String , val eTag : String? , val expireBy : Long = 0 ) {
0 commit comments