From 8e2ee316db85af5f67ca2fddc0e32e652bef28d4 Mon Sep 17 00:00:00 2001 From: kean Date: Sat, 15 Jul 2023 09:07:18 -0400 Subject: [PATCH] Deprecate DataCache/isCompressionEnabled --- CHANGELOG.md | 7 ++++--- .../Performance/Caching/cache-layers.md | 3 --- Sources/Nuke/Caching/DataCache.swift | 21 ++++++++----------- .../DataCachePeformanceTests.swift | 13 ------------ Tests/NukeTests/DataCacheTests.swift | 17 --------------- 5 files changed, 13 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edd1228b6..936d42300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ # Nuke 12 -## Nuke 12.1.4 +## Nuke 12.2 *Upcoming* - Upgrade to [`CryptoKit`](https://developer.apple.com/documentation/cryptokit) from `CommonCrypto` and optimize how cryptographic hashes are converted to strings (used as filenames in `DataCache`) +- Deprecate `DataCache/isCompressionEnabled`. It was initially added as a general-purpose feature, but it's not recommended to be used with most image formats. ## Nuke 12.1.3 @@ -27,7 +28,7 @@ - Update unit tests – https://github.com/kean/Nuke/pull/701 by @woxtu - Fix upcoming warnings in Xcode 15 -## Nuke 12.1.0 +## Nuke 12.1 *Mar 25, 2023* @@ -36,7 +37,7 @@ - Fix an issue with `.videoAssetKey` value missing from `ImageContainer` - Fix an issue with `.gif` being encoded as `.jpeg` when `.storeEncodedImages` policy is used -## Nuke 12.0.0 +## Nuke 12.0 *Mar 4, 2023* diff --git a/Documentation/Nuke.docc/Performance/Caching/cache-layers.md b/Documentation/Nuke.docc/Performance/Caching/cache-layers.md index 6757cdece..7f787af00 100644 --- a/Documentation/Nuke.docc/Performance/Caching/cache-layers.md +++ b/Documentation/Nuke.docc/Performance/Caching/cache-layers.md @@ -95,9 +95,6 @@ let dataCache = try DataCache(name: "my-cache") dataCache.sizeLimit = 1024 * 1024 * 100 // 100 MB -// Reduces space usage but adds a slight performance hit -dataCache.isCompressionEnabled = true - dataCache.storeData(data, for: "key") if dataCache.containsData(for: "key") { print("Data is cached") diff --git a/Sources/Nuke/Caching/DataCache.swift b/Sources/Nuke/Caching/DataCache.swift index 8a381d745..1fbf5b87c 100644 --- a/Sources/Nuke/Caching/DataCache.swift +++ b/Sources/Nuke/Caching/DataCache.swift @@ -57,16 +57,13 @@ public final class DataCache: DataCaching, @unchecked Sendable { /// other subsystems for the resources. private var initialSweepDelay: TimeInterval = 10 - /// Enables compression. Disabled by default. - /// - /// Enabling compression significantly decreases disk usage allowing you - /// to store more images or reduce the cache size limit. - /// - /// - warning: There is a significant performance hit associated with compression. - /// - /// - note: If enabled, uses `lzfse` compression algorithm that offers - /// optimal performance on Apple platforms. - public var isCompressionEnabled = false + // Deprecated in Nuke 12.2 + @available(*, deprecated, message: "It's not recommended to use compression with the popular image formats that already compress the data") + public var isCompressionEnabled: Bool { + get { _isCompressionEnabled } + set { _isCompressionEnabled = newValue } + } + var _isCompressionEnabled = false // Staging @@ -333,14 +330,14 @@ public final class DataCache: DataCaching, @unchecked Sendable { // MARK: Compression private func compressed(_ data: Data) throws -> Data { - guard isCompressionEnabled else { + guard _isCompressionEnabled else { return data } return try (data as NSData).compressed(using: .lzfse) as Data } private func decompressed(_ data: Data) throws -> Data { - guard isCompressionEnabled else { + guard _isCompressionEnabled else { return data } return try (data as NSData).decompressed(using: .lzfse) as Data diff --git a/Tests/NukePerformanceTests/DataCachePeformanceTests.swift b/Tests/NukePerformanceTests/DataCachePeformanceTests.swift index 1f8a6448b..d48357175 100644 --- a/Tests/NukePerformanceTests/DataCachePeformanceTests.swift +++ b/Tests/NukePerformanceTests/DataCachePeformanceTests.swift @@ -47,19 +47,6 @@ class DataCachePeformanceTests: XCTestCase { } } - func testReadFlushedPerformanceWithCompression() { - cache.isCompressionEnabled = true - count = 100 - - populate() - - measure { - for idx in 0..