Skip to content

Commit

Permalink
Merge pull request #130 from spotify/dflems/20210924-ci
Browse files Browse the repository at this point in the history
Xcode 13 support, fix some warnings, remove suppressions
  • Loading branch information
dflems committed Sep 24, 2021
2 parents 974682a + 1b5e24f commit 12f1d72
Show file tree
Hide file tree
Showing 72 changed files with 134 additions and 117 deletions.
2 changes: 1 addition & 1 deletion SPTPersistentCache.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = SPTPersistentCache;
LastUpgradeCheck = 1210;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = Spotify;
TargetAttributes = {
0510FF121BA2FF7A00ED0766 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1210"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = SPT;
LastUpgradeCheck = 1210;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = Spotify;
TargetAttributes = {
055725F91C65280000EF6787 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1210"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand All @@ -25,7 +25,7 @@
@interface DetailViewController : UIViewController

@property (nonatomic, strong) SPTPersistentCache *persistentDataCache;
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) NSObject *detailItem;
@property (nonatomic, weak, readwrite) IBOutlet UIImageView *detailImageView;

@end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion SPTPersistentCacheDemo/SPTPersistentCacheDemo/main.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion SPTPersistentCacheFramework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleVersion</key>
<string>1.1.1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 Spotify. All rights reserved.</string>
<string>Copyright © 2015-2021 Spotify. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = SPTPersistentCache;
LastUpgradeCheck = 1210;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = Spotify;
TargetAttributes = {
0520219B1C737DBE003A4FB4 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1210"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1210"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Sources/NSError+SPTPersistentCacheDomainErrors.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/NSError+SPTPersistentCacheDomainErrors.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCache+Private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
64 changes: 42 additions & 22 deletions Sources/SPTPersistentCache.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -61,6 +61,13 @@ void SPTPersistentCacheSafeDispatch(_Nullable dispatch_queue_t queue, _Nonnull d
}
}

@interface SPTPersistentCacheFileInfo : NSObject
@property (nonatomic, strong, readonly) NSString *fileName;
@property (nonatomic, strong, readonly) NSDate *mdate;
@property (nonatomic, assign, readonly) off_t fileSize;
- (instancetype)initWithFileName:(NSString *)fileName mdate:(NSDate *)mdate fileSize:(off_t)fileSize;
@end

// Class extension exists in SPTPersistentCache+Private.h

#pragma mark - SPTPersistentCache
Expand Down Expand Up @@ -959,22 +966,22 @@ - (BOOL)pruneBySize
}

// Find all the image names and attributes and sort oldest last
NSMutableArray *images = [self storedImageNamesAndAttributes];
NSMutableArray<SPTPersistentCacheFileInfo *> *files = [self storedFileNamesAndAttributes];

// Find the free space on the disk
SPTPersistentCacheDiskSize currentCacheSize = (SPTPersistentCacheDiskSize)[self lockedItemsSizeInBytes];
for (NSDictionary *image in images) {
currentCacheSize += [image[SPTDataCacheFileAttributesKey][NSFileSize] integerValue];
for (SPTPersistentCacheFileInfo *file in files) {
currentCacheSize += file.fileSize;
}

SPTPersistentCacheDiskSize optimalCacheSize = [self.dataCacheFileManager optimizedDiskSizeForCacheSize:currentCacheSize];

// Remove oldest data until we reach acceptable cache size
while (currentCacheSize > optimalCacheSize && images.count) {
NSDictionary *image = images.lastObject;
[images removeLastObject];
while (currentCacheSize > optimalCacheSize && files.count) {
SPTPersistentCacheFileInfo *file = files.lastObject;
[files removeLastObject];

NSString *fileName = image[SPTDataCacheFileNameKey];
NSString *fileName = file.fileName;
NSError *localError = nil;
if (fileName.length > 0 && ![self.fileManager removeItemAtPath:fileName error:&localError]) {
[self debugOutput:@"PersistentDataCache: %@ ERROR %@", @(__PRETTY_FUNCTION__), [localError localizedDescription]];
Expand All @@ -983,12 +990,12 @@ - (BOOL)pruneBySize
[self debugOutput:@"PersistentDataCache: evicting by size key:%@", fileName.lastPathComponent];
}

currentCacheSize -= [image[SPTDataCacheFileAttributesKey][NSFileSize] integerValue];
currentCacheSize -= file.fileSize;
}
return YES;
}

- (NSMutableArray *)storedImageNamesAndAttributes
- (NSMutableArray<SPTPersistentCacheFileInfo *> *)storedFileNamesAndAttributes
{
NSURL *urlPath = [NSURL fileURLWithPath:self.options.cachePath];

Expand All @@ -1001,7 +1008,7 @@ - (NSMutableArray *)storedImageNamesAndAttributes
errorHandler:nil];

// An array to store the all the enumerated file names in
NSMutableArray *images = [NSMutableArray array];
NSMutableArray<SPTPersistentCacheFileInfo *> *files = [NSMutableArray array];

// Enumerate the dirEnumerator results, each value is stored in allURLs
NSURL *theURL = nil;
Expand Down Expand Up @@ -1043,28 +1050,26 @@ - (NSMutableArray *)storedImageNamesAndAttributes
Use modification time even for files with TTL
Files with TTL have updateTime set once on creation.
*/
NSDate *mdate = [NSDate dateWithTimeIntervalSince1970:(fileStat.st_mtimespec.tv_sec + fileStat.st_mtimespec.tv_nsec*1e9)];
NSNumber *fsize = [NSNumber numberWithLongLong:fileStat.st_size];
NSDictionary *values = @{NSFileModificationDate : mdate, NSFileSize: fsize};

[images addObject:@{ SPTDataCacheFileNameKey : filePathString,
SPTDataCacheFileAttributesKey : values }];
NSDate *mdate = [NSDate dateWithTimeIntervalSince1970:(fileStat.st_mtimespec.tv_sec + fileStat.st_mtimespec.tv_nsec*1e9)];
SPTPersistentCacheFileInfo *info = [[SPTPersistentCacheFileInfo alloc] initWithFileName:filePathString
mdate:mdate
fileSize:fileStat.st_size];
[files addObject:info];
}
} else {
[self debugOutput:@"Unable to fetch isDir#5 attribute:%@", theURL];
}
}

// Oldest goes last
NSComparisonResult(^SPTSortFilesByModificationDate)(id, id) = ^NSComparisonResult(NSDictionary *file1, NSDictionary *file2) {
NSDate *date1 = file1[SPTDataCacheFileAttributesKey][NSFileModificationDate];
NSDate *date2 = file2[SPTDataCacheFileAttributesKey][NSFileModificationDate];
return [date2 compare:date1];
NSComparisonResult(^SPTSortFilesByModificationDate)(id, id) = ^NSComparisonResult(SPTPersistentCacheFileInfo *file1, SPTPersistentCacheFileInfo *file2) {
return [file2.mdate compare:file1.mdate];
};

NSArray *sortedImages = [images sortedArrayUsingComparator:SPTSortFilesByModificationDate];
[files sortUsingComparator:SPTSortFilesByModificationDate];

return [sortedImages mutableCopy];
return files;
}

- (NSTimeInterval)currentDateTimeInterval
Expand All @@ -1090,3 +1095,18 @@ - (void)logTimingForKey:(NSString *)key method:(SPTPersistentCacheDebugMethodTyp
}

@end

@implementation SPTPersistentCacheFileInfo

- (instancetype)initWithFileName:(NSString *)fileName mdate:(NSDate *)mdate fileSize:(off_t)fileSize
{
self = [super init];
if (self) {
_fileName = fileName;
_mdate = mdate;
_fileSize = fileSize;
}
return self;
}

@end
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheDebugUtilities.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheDebugUtilities.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheFileManager+Private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheFileManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheFileManager.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheGarbageCollector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheGarbageCollector.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheHeader.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheObjectDescription.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheObjectDescription.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
4 changes: 2 additions & 2 deletions Sources/SPTPersistentCacheOptions.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -108,7 +108,7 @@ - (void)setDefaultExpirationPeriod:(NSUInteger)defaultExpirationPeriod

- (id)copyWithZone:(NSZone *)zone
{
SPTPersistentCacheOptions * const copy = [[self.class allocWithZone:zone] init];
SPTPersistentCacheOptions * const copy = [(SPTPersistentCacheOptions *)[self.class allocWithZone:zone] init];

copy.cacheIdentifier = self.cacheIdentifier;
copy.cachePath = self.cachePath;
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCachePosixWrapper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCachePosixWrapper.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheRecord+Private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheRecord.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTPersistentCacheResponse+Private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020 Spotify AB.
Copyright (c) 2015-2021 Spotify AB.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
Loading

0 comments on commit 12f1d72

Please sign in to comment.