Skip to content

Commit

Permalink
Enhance V2EXService with caching configuration for improved network p…
Browse files Browse the repository at this point in the history
…erformance

- Added a custom URLCache with 5MB memory and 20MB disk capacity to V2EXService.
- Configured URLSession to use the new cache and set request cache policy to return cached data if available, enhancing data retrieval efficiency.
  • Loading branch information
ygsgdbd committed Dec 12, 2024
1 parent e1904eb commit a8cfa08
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions V2Bar/Sources/Network/V2EXService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ actor V2EXService {
private let session: Session

private init() {
let cache = URLCache(
memoryCapacity: 5 * 1024 * 1024, // 5MB 内存缓存
diskCapacity: 20 * 1024 * 1024 // 20MB 磁盘缓存
)

let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30
configuration.timeoutIntervalForResource = 300
configuration.waitsForConnectivity = true
configuration.urlCache = cache
configuration.requestCachePolicy = .returnCacheDataElseLoad

session = Session(configuration: configuration)
}
Expand Down

0 comments on commit a8cfa08

Please sign in to comment.