summaryrefslogtreecommitdiff
path: root/Sora/Data/Booru
diff options
context:
space:
mode:
Diffstat (limited to 'Sora/Data/Booru')
-rw-r--r--Sora/Data/Booru/BooruManager.swift11
1 files changed, 8 insertions, 3 deletions
diff --git a/Sora/Data/Booru/BooruManager.swift b/Sora/Data/Booru/BooruManager.swift
index 8f6fbd7..5530d7c 100644
--- a/Sora/Data/Booru/BooruManager.swift
+++ b/Sora/Data/Booru/BooruManager.swift
@@ -22,7 +22,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng
// MARK: - Private Properties
private var currentTask: Task<Void, Never>?
private let pageCache = NSCache<NSString, BooruPageCacheEntry>() // swiftlint:disable:this legacy_objc_type
- private let cacheDuration: TimeInterval = 300
+ private let cacheDuration: TimeInterval
private let credentials: BooruProviderCredentials?
private let userAgent: String
@@ -38,11 +38,16 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng
var canGoForwardInHistory: Bool { historyIndex < searchHistory.count - 1 }
// MARK: - Initialisation
- init(_ provider: BooruProvider, credentials: BooruProviderCredentials? = nil) {
+ init(
+ _ provider: BooruProvider,
+ credentials: BooruProviderCredentials? = nil,
+ cacheDuration: TimeInterval = 300
+ ) {
self.provider = provider
self.flavor = BooruProviderFlavor(provider: provider)
self.domain = provider.domain
self.credentials = credentials
+ self.cacheDuration = cacheDuration
pageCache.countLimit = 50
pageCache.totalCostLimit = 50 * 1_024 * 1_024
@@ -132,7 +137,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng
expiration: cacheDuration
)
- pageCache.setObject(cacheEntry, forKey: cacheKey)
+ pageCache.setObject(cacheEntry, forKey: cacheKey, cost: finalPosts.count)
withAnimation(nil) {
updatePosts(finalPosts, replace: replace)