Skip to content

Commit

Permalink
Deprecate DataCache/isCompressionEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jul 15, 2023
1 parent e7e3342 commit 8e2ee31
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 48 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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*

Expand All @@ -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*

Expand Down
3 changes: 0 additions & 3 deletions Documentation/Nuke.docc/Performance/Caching/cache-layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 9 additions & 12 deletions Sources/Nuke/Caching/DataCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions Tests/NukePerformanceTests/DataCachePeformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,6 @@ class DataCachePeformanceTests: XCTestCase {
}
}

func testReadFlushedPerformanceWithCompression() {
cache.isCompressionEnabled = true
count = 100

populate()

measure {
for idx in 0..<count {
_ = self.cache["\(idx)"]
}
}
}

func populate() {
for idx in 0..<count {
cache["\(idx)"] = generateRandomData()
Expand Down
17 changes: 0 additions & 17 deletions Tests/NukeTests/DataCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,23 +333,6 @@ class DataCacheTests: XCTestCase {
XCTAssertEqual(data, blob)
}

// MARK: Compression

func testCompression() throws {
// GIVEN
cache.isCompressionEnabled = true

// WHEN
cache["key"] = Test.data
XCTAssertEqual(cache["key"], Test.data)
cache.flush()
XCTAssertEqual(cache["key"], Test.data)

// THEN
let raw = try Data(contentsOf: XCTUnwrap(cache.url(for: "key")))
XCTAssertTrue(raw.count < Test.data.count)
}

// MARK: Flush

func testFlush() {
Expand Down

0 comments on commit 8e2ee31

Please sign in to comment.