diff --git a/CHANGELOG.md b/CHANGELOG.md index b66ea0255..4ba0445da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # Parse-Swift Changelog ### main -[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.13.0...main) +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.13.1...main) * _Contributing to this repo? Add info about your change here to be included in the next release_ +### 4.13.1 +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.13.0...4.13.1) + +__Fixes__ +- Remove ParseFile caching due to OS not having a natural way to cache files. Instead, if developers want to access a saved ParseFile, they should check the download directory for the respective file name ([#414](https://github.com/parse-community/Parse-Swift/pull/414)), thanks to [Corey Baker](https://github.com/cbaker6). + ### 4.13.0 [Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.12.0...4.13.0) diff --git a/Sources/ParseSwift/Extensions/URLSession.swift b/Sources/ParseSwift/Extensions/URLSession.swift index 9d296df13..60ff25e92 100644 --- a/Sources/ParseSwift/Extensions/URLSession.swift +++ b/Sources/ParseSwift/Extensions/URLSession.swift @@ -296,21 +296,6 @@ internal extension URLSession { location: location, urlResponse: urlResponse, responseError: responseError, mapper: mapper) - if case .success(let file) = result { - guard let response = urlResponse, - let parseFile = file as? ParseFile, - let fileLocation = parseFile.localURL, - let data = try? ParseCoding.jsonEncoder().encode(fileLocation) else { - completion(result) - return - } - if URLSession.parse.configuration.urlCache?.cachedResponse(for: request) == nil { - URLSession.parse.configuration.urlCache? - .storeCachedResponse(.init(response: response, - data: data), - for: request) - } - } completion(result) } #if compiler(>=5.5.2) && canImport(_Concurrency) diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index e4af0d4c2..f94e08c36 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -10,7 +10,7 @@ import Foundation enum ParseConstants { static let sdk = "swift" - static let version = "4.12.0" + static let version = "4.13.1" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" static let fileManagementLibraryDirectory = "Library/" diff --git a/Tests/ParseSwiftTests/ParseFileTests.swift b/Tests/ParseSwiftTests/ParseFileTests.swift index 3bd2d17ca..7c08a8948 100644 --- a/Tests/ParseSwiftTests/ParseFileTests.swift +++ b/Tests/ParseSwiftTests/ParseFileTests.swift @@ -1123,34 +1123,20 @@ class ParseFileTests: XCTestCase { // swiftlint:disable:this type_body_length XCTAssertEqual(fetchedFile.url, response.url) XCTAssertNotNil(fetchedFile.localURL) - // Cache policy flakey on older Swift versions - #if compiler(>=5.5.0) // Remove URL mocker so we can check cache MockURLProtocol.removeAll() - - let fetchedFile2 = try parseFile.fetch(options: [.cachePolicy(.returnCacheDataDontLoad)]) - XCTAssertEqual(fetchedFile2.name, fetchedFile.name) - XCTAssertEqual(fetchedFile2.url, fetchedFile.url) - XCTAssertNotNil(fetchedFile2.localURL) - - // More cache tests - guard let currentMemoryUsage = URLSession.parse.configuration.urlCache?.currentMemoryUsage, - let currentDiskUsage = URLSession.parse.configuration.urlCache?.currentDiskUsage else { - XCTFail("Should have unwrapped") - return - } - XCTAssertGreaterThan(currentMemoryUsage, 0) - XCTAssertGreaterThan(currentDiskUsage, 0) - ParseSwift.clearCache() - guard let updatedMemoryUsage = URLSession.parse.configuration.urlCache?.currentMemoryUsage else { - XCTFail("Should have unwrapped") - return + do { + _ = try parseFile.fetch(options: [.cachePolicy(.returnCacheDataDontLoad)]) + } catch { + guard let parseError = error as? ParseError else { + XCTFail("Should have casted") + return + } + XCTAssertTrue(parseError.message.contains("No response")) } - XCTAssertLessThan(updatedMemoryUsage, currentMemoryUsage) - #endif } - func testFetchFileWithDirInName() throws { + func testFetchFileWithDirectoryInName() throws { // swiftlint:disable:next line_length guard let parseFileURL = URL(string: "http://localhost:1337/1/files/applicationId/d3a37aed0672a024595b766f97133615_logo.svg") else { XCTFail("Should create URL") @@ -1181,31 +1167,17 @@ class ParseFileTests: XCTestCase { // swiftlint:disable:this type_body_length } XCTAssertFalse(localURL.pathComponents.contains("myFolder")) - // Cache policy flakey on older Swift versions - #if compiler(>=5.5.0) // Remove URL mocker so we can check cache MockURLProtocol.removeAll() - - let fetchedFile2 = try parseFile.fetch(options: [.cachePolicy(.returnCacheDataDontLoad)]) - XCTAssertEqual(fetchedFile2.name, fetchedFile.name) - XCTAssertEqual(fetchedFile2.url, fetchedFile.url) - XCTAssertNotNil(fetchedFile2.localURL) - - // More cache tests - guard let currentMemoryUsage = URLSession.parse.configuration.urlCache?.currentMemoryUsage, - let currentDiskUsage = URLSession.parse.configuration.urlCache?.currentDiskUsage else { - XCTFail("Should have unwrapped") - return - } - XCTAssertGreaterThan(currentMemoryUsage, 0) - XCTAssertGreaterThan(currentDiskUsage, 0) - ParseSwift.clearCache() - guard let updatedMemoryUsage = URLSession.parse.configuration.urlCache?.currentMemoryUsage else { - XCTFail("Should have unwrapped") - return + do { + _ = try parseFile.fetch(options: [.cachePolicy(.returnCacheDataDontLoad)]) + } catch { + guard let parseError = error as? ParseError else { + XCTFail("Should have casted") + return + } + XCTAssertTrue(parseError.message.contains("No response")) } - XCTAssertLessThan(updatedMemoryUsage, currentMemoryUsage) - #endif } func testFetchFileProgress() throws {