Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow backup opt out #121

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/SPTPersistentCacheFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Sources/SPTPersistentCacheOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ - (instancetype)init
_cachePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"/com.spotify.temppersistent.image.cache"];
_cacheIdentifier = @"persistent.cache";
_useDirectorySeparation = YES;
_shouldExcludeFromBackup = NO;
Copy link

@SPTElyasn SPTElyasn Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aodhol You probably need to provide the deep copy of this. You have it down there in copyWithZone

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super important but would be nice to include it in debugDescription.


_garbageCollectionInterval = SPTPersistentCacheDefaultGCIntervalSec;
_defaultExpirationPeriod = SPTPersistentCacheDefaultExpirationTimeSec;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions include/SPTPersistentCache/SPTPersistentCacheOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aodhol In order to avoid any confusion, would be nice to mention the default value here maybe.

@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
Expand Down