From 38746145911136b9f08f6a1f2f805665299450c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Thu, 16 Jan 2020 18:36:10 +0100 Subject: [PATCH 01/10] Add option for excluding the cache directory from backup --- Sources/SPTPersistentCacheOptions.m | 2 ++ include/SPTPersistentCache/SPTPersistentCacheOptions.h | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/Sources/SPTPersistentCacheOptions.m b/Sources/SPTPersistentCacheOptions.m index 36f2234..2944c24 100644 --- a/Sources/SPTPersistentCacheOptions.m +++ b/Sources/SPTPersistentCacheOptions.m @@ -51,6 +51,7 @@ - (instancetype)init _cachePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"/com.spotify.temppersistent.image.cache"]; _cacheIdentifier = @"persistent.cache"; _useDirectorySeparation = YES; + _shouldExcludeFromBackup = NO; _garbageCollectionInterval = SPTPersistentCacheDefaultGCIntervalSec; _defaultExpirationPeriod = SPTPersistentCacheDefaultExpirationTimeSec; @@ -113,6 +114,7 @@ - (id)copyWithZone:(NSZone *)zone copy.cacheIdentifier = self.cacheIdentifier; copy.cachePath = self.cachePath; copy.useDirectorySeparation = self.useDirectorySeparation; + copy.shouldExcludeFromBackup = self.shouldExcludeFromBackup; copy.garbageCollectionInterval = self.garbageCollectionInterval; copy.defaultExpirationPeriod = self.defaultExpirationPeriod; diff --git a/include/SPTPersistentCache/SPTPersistentCacheOptions.h b/include/SPTPersistentCache/SPTPersistentCacheOptions.h index 78efc42..a603ffb 100644 --- a/include/SPTPersistentCache/SPTPersistentCacheOptions.h +++ b/include/SPTPersistentCache/SPTPersistentCacheOptions.h @@ -114,6 +114,14 @@ FOUNDATION_EXPORT const NSUInteger SPTPersistentCacheMinimumExpirationLimit; */ @property (nonatomic, copy) NSString *cachePath; +/** + Excludes the cache directory from backup. + @discussion Some users may wish to have the cache directory excluded from backup. + @note This will only affect the first time the cache directory is created. Changing this value later will have no effect and would require the removal of the + cache directory in order to change. + */ +@property (nonatomic, assign) BOOL shouldExcludeFromBackup; + /** Whether directory separation of cache records should be used. @discussion When enabled cached records are separate into direcectories based on the first two (2) characters in From 01899eb4f7d13d2f9343aead18ece402419eddf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Thu, 16 Jan 2020 18:37:58 +0100 Subject: [PATCH 02/10] Set the 'do not backup' resource value for the directory --- Sources/SPTPersistentCacheFileManager.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/SPTPersistentCacheFileManager.m b/Sources/SPTPersistentCacheFileManager.m index 79c55fd..49b96e1 100644 --- a/Sources/SPTPersistentCacheFileManager.m +++ b/Sources/SPTPersistentCacheFileManager.m @@ -59,6 +59,13 @@ - (BOOL)createCacheDirectory return NO; } + + [[NSURL fileURLWithPath:self.options.cachePath] setResourceValue:@(self.options.shouldExcludeFromBackup) forKey:NSURLIsExcludedFromBackupKey error:&error]; + if (error) { + SPTPersistentCacheSafeDebugCallback([NSString stringWithFormat: + @"PersistentDataCache: Resource value: %@ could not be set for key 'NSURLIsExcludedFromBackupKey' because: %@", + @(self.options.shouldExcludeFromBackup), error], self.debugOutput); + } } return YES; From 3337742e91a7576acf87b2ca9d71c8bdc6eeb2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Fri, 17 Jan 2020 13:10:59 +0100 Subject: [PATCH 03/10] Bump version strings --- Tests/Info.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Info.plist b/Tests/Info.plist index 7659d3e..f6e7514 100644 --- a/Tests/Info.plist +++ b/Tests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.1.1 + 1.1.2 CFBundleSignature ???? CFBundleVersion - 1.1.1 + 1.1.2 From 30f0da142a40843c355c1c4e545255d8d35971d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Fri, 17 Jan 2020 16:03:30 +0100 Subject: [PATCH 04/10] Add new option to description --- Sources/SPTPersistentCacheOptions.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/SPTPersistentCacheOptions.m b/Sources/SPTPersistentCacheOptions.m index 2944c24..9bc47c7 100644 --- a/Sources/SPTPersistentCacheOptions.m +++ b/Sources/SPTPersistentCacheOptions.m @@ -148,6 +148,7 @@ - (NSString *)debugDescription return SPTPersistentCacheObjectDescription(self, self.cacheIdentifier, @"cache-identifier", self.cachePath, @"cache-path", + self.shouldExcludeFromBackup, @"exclude-from-backup", self.identifierForQueue, @"identifier-for-queue", @(self.useDirectorySeparation), @"use-directory-separation", @(self.garbageCollectionInterval), @"garbage-collection-interval", From ece3d0ad92933f1acfe3dea9b763eb3303c7f7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Fri, 17 Jan 2020 16:03:57 +0100 Subject: [PATCH 05/10] Make comment clearer --- include/SPTPersistentCache/SPTPersistentCacheOptions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/SPTPersistentCache/SPTPersistentCacheOptions.h b/include/SPTPersistentCache/SPTPersistentCacheOptions.h index a603ffb..1f7694f 100644 --- a/include/SPTPersistentCache/SPTPersistentCacheOptions.h +++ b/include/SPTPersistentCache/SPTPersistentCacheOptions.h @@ -117,8 +117,8 @@ FOUNDATION_EXPORT const NSUInteger SPTPersistentCacheMinimumExpirationLimit; /** Excludes the cache directory from backup. @discussion Some users may wish to have the cache directory excluded from backup. - @note This will only affect the first time the cache directory is created. Changing this value later will have no effect and would require the removal of the - cache directory in order to change. + @note This will only affect the first time the cache directory is created. Changing this value later will have no effect and would require a new cache directory + to be created in order to change. */ @property (nonatomic, assign) BOOL shouldExcludeFromBackup; From 228adb1c022cae24c79745e85b337615f2d35cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Wed, 22 Jan 2020 14:48:01 +0100 Subject: [PATCH 06/10] Set the resource value each time --- Sources/SPTPersistentCacheFileManager.m | 16 +++++++++------- .../SPTPersistentCacheOptions.h | 2 -- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/SPTPersistentCacheFileManager.m b/Sources/SPTPersistentCacheFileManager.m index 49b96e1..8344e97 100644 --- a/Sources/SPTPersistentCacheFileManager.m +++ b/Sources/SPTPersistentCacheFileManager.m @@ -59,15 +59,17 @@ - (BOOL)createCacheDirectory return NO; } + } - [[NSURL fileURLWithPath:self.options.cachePath] setResourceValue:@(self.options.shouldExcludeFromBackup) forKey:NSURLIsExcludedFromBackupKey error:&error]; - if (error) { - SPTPersistentCacheSafeDebugCallback([NSString stringWithFormat: - @"PersistentDataCache: Resource value: %@ could not be set for key 'NSURLIsExcludedFromBackupKey' because: %@", - @(self.options.shouldExcludeFromBackup), error], self.debugOutput); - } + NSError *error = nil; + [[NSURL fileURLWithPath:self.options.cachePath] setResourceValue:@(self.options.shouldExcludeFromBackup) forKey:NSURLIsExcludedFromBackupKey error:&error]; + + if (error) { + SPTPersistentCacheSafeDebugCallback([NSString stringWithFormat: + @"PersistentDataCache: Resource value: %@ could not be set for key 'NSURLIsExcludedFromBackupKey' because: %@", + @(self.options.shouldExcludeFromBackup), error], self.debugOutput); } - + return YES; } diff --git a/include/SPTPersistentCache/SPTPersistentCacheOptions.h b/include/SPTPersistentCache/SPTPersistentCacheOptions.h index 1f7694f..ed54c89 100644 --- a/include/SPTPersistentCache/SPTPersistentCacheOptions.h +++ b/include/SPTPersistentCache/SPTPersistentCacheOptions.h @@ -117,8 +117,6 @@ FOUNDATION_EXPORT const NSUInteger SPTPersistentCacheMinimumExpirationLimit; /** Excludes the cache directory from backup. @discussion Some users may wish to have the cache directory excluded from backup. - @note This will only affect the first time the cache directory is created. Changing this value later will have no effect and would require a new cache directory - to be created in order to change. */ @property (nonatomic, assign) BOOL shouldExcludeFromBackup; From c8988ee5c14470d48fbfeaa919bdd2058ba3477a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Wed, 22 Jan 2020 18:56:34 +0100 Subject: [PATCH 07/10] Bump version --- SPTPersistentCache.podspec | 2 +- SPTPersistentCacheFramework/Info.plist | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SPTPersistentCache.podspec b/SPTPersistentCache.podspec index b5425e1..4197495 100644 --- a/SPTPersistentCache.podspec +++ b/SPTPersistentCache.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SPTPersistentCache" - s.version = "1.1.1" + s.version = "1.1.2" s.summary = "SPTPersistentCache is a fast, binary, LRU cache used in the Spotify iOS app" s.description = <<-DESC diff --git a/SPTPersistentCacheFramework/Info.plist b/SPTPersistentCacheFramework/Info.plist index 205d5f6..7e868aa 100644 --- a/SPTPersistentCacheFramework/Info.plist +++ b/SPTPersistentCacheFramework/Info.plist @@ -19,9 +19,9 @@ CFBundleSignature ???? CFBundleVersion - 1.1.1 + 1.1.2 NSHumanReadableCopyright - Copyright © 2019 Spotify. All rights reserved. + Copyright © 2020 Spotify. All rights reserved. NSPrincipalClass From defb567174377859bf16f5af17f5e736d1034398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Wed, 22 Jan 2020 18:58:13 +0100 Subject: [PATCH 08/10] Update change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e16d84..bd84ce7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. SPTPersistentCache adheres to [Semantic Versioning](http://semver.org/). -- +## [1.1.2](https://github.com/spotify/SPTPersistentCache/releases/tag/1.1.2) + +### Added +* SPTPersistentCacheOptions property allowing users to opt out of system backup. + ## [1.1.1](https://github.com/spotify/SPTPersistentCache/releases/tag/1.1.1) _Released on 2017-08-15._ From 4346242aa28c66cce09ef8a89d867b338584e33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Wed, 22 Jan 2020 18:59:23 +0100 Subject: [PATCH 09/10] Fix error in example --- README.md | 2 +- .../SPTPersistentCacheDemo/MasterViewController.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2a52bd5..8020321 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ For an example of this framework's usage, see the demo application `SPTPersisten ### Creating the SPTPersistentCache It is best to use different caches for different types of data you want to store, and not just one big cache for your entire application. However, only create one `SPTPersistentCache` instance for each cache, otherwise you might encounter anomalies when the two different caches end up writing to the same file. ```objc -NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject stringByAppendingString:@"com.spotify.demo.image.cache"]; +NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"com.spotify.demo.image.cache"]; SPTPersistentCacheOptions *options = [SPTPersistentCacheOptions new]; options.cachePath = cachePath; diff --git a/SPTPersistentCacheDemo/SPTPersistentCacheDemo/MasterViewController.m b/SPTPersistentCacheDemo/SPTPersistentCacheDemo/MasterViewController.m index 9fb9513..f4b15bf 100644 --- a/SPTPersistentCacheDemo/SPTPersistentCacheDemo/MasterViewController.m +++ b/SPTPersistentCacheDemo/SPTPersistentCacheDemo/MasterViewController.m @@ -42,7 +42,7 @@ - (void)viewDidLoad NSString *cacheIdentifier = @"com.spotify.demo.image.cache"; NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, - YES).firstObject stringByAppendingString:cacheIdentifier]; + YES).firstObject stringByAppendingPathComponent:cacheIdentifier]; SPTPersistentCacheOptions *options = [SPTPersistentCacheOptions new]; options.cachePath = cachePath; From e87d87a6b88f5981dfb4ad6bd51b6a7470fa4dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aodh=20=C3=93=20Lion=C3=A1ird?= Date: Wed, 22 Jan 2020 18:59:40 +0100 Subject: [PATCH 10/10] Update version --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8020321..74bca61 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ $ gem install cocoapods ``` Then simply add `SPTPersistentCache` to your `Podfile`. ``` -pod 'SPTPersistentCache', '~> 1.1.1' +pod 'SPTPersistentCache', '~> 1.1.2' ``` Lastly let CocoaPods do its thing by running: ```shell @@ -48,7 +48,7 @@ $ brew install carthage ``` You will also need to add `SPTPersistentCache` to your `Cartfile`: ``` -github "spotify/SPTPersistentCache" ~> 1.1.1 +github "spotify/SPTPersistentCache" ~> 1.1.2 ``` After that is all said and done, let Carthage pull in SPTPersistentCache like so: ```shell