1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00

storage: set disk cache expiry dates for images

This commit adds expiry dates for images added to the Kingfisher cache.
The expiry date depends on the context of the image:

- Images from notes expire after a week
- Images from profile banners expire after two weeks
- Profile pictures never expire.

Test
----

Device: iPhone 14 Pro (Simulator), iOS: 17.0
Special remarks: Requires minor local mods and debugger connection
Steps:

1. Locally change the note image expiry to 5 seconds
2. Set a breakpoint in `removeExpiredValues` function in `DiskStorage.swift` in Kingfisher
3. Disable breakpoints for now
4. Start Damus and go to the profile feed of someone new
5. Scroll down through the images for about a minute
6. Turn on breakpoints
7. Switch to a different app in the simulator (Make Damus go to background mode)
8. Wait for a few seconds. Debugger should hit the breakpoint set. PASS
9. Take note of the fileURLs of the images being deleted
10. Go to that directory where the fileURLs are in via Finder
11. Look at some of the images being deleted. Perhaps save a copy for comparison.
12. Turn off breakpoints, resume execution and go back to Damus
13. Scroll back up. Some images there should match the images being automatically deleted from the cache. PASS

Closes: https://github.com/damus-io/damus/issues/1565
Changelog-Added: Add expiry date for images in cache to be auto-deleted after a preset time to save space on storage
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D’Aquino 2023-10-14 00:42:27 +00:00 committed by William Casarin
parent 439f9974c5
commit 82fba88cc4

View File

@ -28,6 +28,18 @@ extension KFOptionSetter {
options.scaleFactor = UIScreen.main.scale
options.onlyLoadFirstFrame = disable_animation
switch imageContext {
case .pfp:
options.diskCacheExpiration = .never
break
case .banner:
options.diskCacheExpiration = .days(14)
break
case .note:
options.diskCacheExpiration = .days(7)
break
}
return self
}