damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 82fba88cc4131f1b2d67c9ac5b56793d634a48e1
parent 439f9974c5e99a7b3626b9a3a02b1ffbf38e6792
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Sat, 14 Oct 2023 00:42:27 +0000

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>

Diffstat:
Mdamus/Util/Extensions/KFOptionSetter+.swift | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/damus/Util/Extensions/KFOptionSetter+.swift b/damus/Util/Extensions/KFOptionSetter+.swift @@ -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 }