You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Breaking changes for 5.0.0. This PR doesn't tag a version: the changelog lists everything under "Unreleased".
Why
About a third of the public API was unused by both PocketLion and Screeners, and some of it didn't work as documented: Entry.meta was always empty, and maxSize was only enforced during a purge. Swift source goes from 1,083 lines to 788.
What changed
Removed
ImageWrapper, Image, the image extensions, JSONArrayWrapper, JSONDictionaryWrapper, JSONArray and JSONDictionary. The package no longer depends on UIKit or AppKit, which also ends the clash with SwiftUI's Image.
DiskConfig.maxSize and Entry.meta.
TypeWrapperStorage. JSONEncoder handles top-level values now, and Data goes to disk as it is instead of base64 in JSON, which is about a quarter smaller.
The public StorageAware protocol, which is now internal. Its docs moved to Storage.
Changed
entry(ofType:forKey:) treats an expired object as missing, like object(ofType:forKey:). Every caller in both apps already checked for that. Disk reads check the expiry first, so an expired object isn't read or decoded.
Files are now named <hash>.cache.
Added
Storage.diskSize(), because Screeners currently works out the folder path itself to measure it. It counts hidden files, and it throws if a folder can't be read rather than reporting a partial size.
README
Cut from about 230 lines to 90: install, usage, configuration, expiry, errors and file protection. The install line says from: "5.0.0", which won't work until that tag exists.
What to look at
On-disk format: caches start empty after upgrading. 4.x files are never read, so an old {"object":...} file can't decode into the wrong type. removeExpiredObjects() removes them during its normal scan, even if they haven't expired, so upgrading adds no launch-time work. Until then they stay on disk, and that includes PocketLion's, because it only calls removeAll().
Everything in the folder that isn't a .cache file is deleted by a purge, hidden files included. The folder belongs to the cache, but this is new behaviour.
Data reads: with no wrapper, asking for Data on a key that holds another type returns its raw JSON bytes instead of a type error.
Upgrading the apps
Screeners: remove maxSize: 0 from Caches.swift in two places, or it won't compile. The !entry.expiry.isExpired checks still compile, but they're now redundant, and getFolderSize can use diskSize().
PocketLion: no code changes. It re-downloads its saved totals once.
Testing
swift test on macOS: 32 tests pass.
xcodebuild test on the iOS Simulator: 33 tests pass.
The tests for the second commit's fixes fail when run against the first commit.
Builds for watchOS, tvOS, visionOS and Mac Catalyst.
A copy of both apps' Cache calls compiles against this branch for iOS, in a file that also imports SwiftUI and uses Image.
Not verified
Neither app has been built against this branch.
Not run on a real device. The file protection checks on gabiPhone were on 4.10.0. The code paths for protection didn't change here.
Storage.playground was edited to remove its image code, but not run.
Removed
- ImageWrapper, the Image typealias, the JSON wrappers and their
typealiases. Neither PocketLion nor Screeners uses them, and the package
no longer depends on UIKit or AppKit.
- DiskConfig.maxSize, which was only enforced by removeExpiredObjects()
and which neither app sets
- Entry.meta, which was always empty
- TypeWrapperStorage. JSONEncoder handles top-level values, and Data now
goes to disk as it is instead of base64 in JSON.
- The public StorageAware protocol. Its docs moved to Storage.
Changed
- entry(ofType:forKey:) treats an expired object as missing. Every caller
was already checking for that. Disk reads check the expiry first, so an
expired object isn't read or decoded.
- Files are named <hash>.cache. Files from 4.x are never read, and
removeExpiredObjects() removes them.
Added
- Storage.diskSize()
Docs
- Cut the README down to what's needed to use the package
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Disk storage still mishandles optional Data serialization, discards enumeration errors, and skips hidden entries, causing read failures, misleading size results, and incomplete cleanup.
- Only write raw bytes for exactly Data. A Data? was written raw, because
as? Data unwraps it, but read back through JSON, which failed.
- Include hidden files in scans, so diskSize() counts them and
removeExpiredObjects() removes them
- Keep directory enumeration errors, so diskSize() can't report 0 or a
partial size as if it were correct when a folder can't be read
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Disk reads can return stale values when entries expire during reading or decoding, and the purge documentation omits that unrelated non-.cache files are deleted.
If an object expires during the disk read or decoding, this returns an expired entry. object(...) also returns that stale value now that StorageAware.object no longer checks expiry after reading. This is reproducible with a custom decoder that runs past the expiry deadline. Keep the early check to skip already-expired files, but recheck the recorded expiry before returning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking changes for 5.0.0. This PR doesn't tag a version: the changelog lists everything under "Unreleased".
Why
About a third of the public API was unused by both PocketLion and Screeners, and some of it didn't work as documented:
Entry.metawas always empty, andmaxSizewas only enforced during a purge. Swift source goes from 1,083 lines to 788.What changed
Removed
ImageWrapper,Image, the image extensions,JSONArrayWrapper,JSONDictionaryWrapper,JSONArrayandJSONDictionary. The package no longer depends on UIKit or AppKit, which also ends the clash with SwiftUI'sImage.DiskConfig.maxSizeandEntry.meta.TypeWrapperStorage.JSONEncoderhandles top-level values now, andDatagoes to disk as it is instead of base64 in JSON, which is about a quarter smaller.StorageAwareprotocol, which is now internal. Its docs moved toStorage.Changed
entry(ofType:forKey:)treats an expired object as missing, likeobject(ofType:forKey:). Every caller in both apps already checked for that. Disk reads check the expiry first, so an expired object isn't read or decoded.<hash>.cache.Added
Storage.diskSize(), because Screeners currently works out the folder path itself to measure it. It counts hidden files, and it throws if a folder can't be read rather than reporting a partial size.README
from: "5.0.0", which won't work until that tag exists.What to look at
{"object":...}file can't decode into the wrong type.removeExpiredObjects()removes them during its normal scan, even if they haven't expired, so upgrading adds no launch-time work. Until then they stay on disk, and that includes PocketLion's, because it only callsremoveAll()..cachefile is deleted by a purge, hidden files included. The folder belongs to the cache, but this is new behaviour.Datareads: with no wrapper, asking forDataon a key that holds another type returns its raw JSON bytes instead of a type error.Upgrading the apps
maxSize: 0fromCaches.swiftin two places, or it won't compile. The!entry.expiry.isExpiredchecks still compile, but they're now redundant, andgetFolderSizecan usediskSize().Testing
swift teston macOS: 32 tests pass.xcodebuild teston the iOS Simulator: 33 tests pass.Image.Not verified
gabiPhonewere on 4.10.0. The code paths for protection didn't change here.Storage.playgroundwas edited to remove its image code, but not run.