spotify / SPTPersistentCache
Showing 14 of 72 files from the diff.
Other files ignored by Codecov
Viewer/main.m has changed.

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file
@@ -108,7 +108,7 @@
Loading
108 108
109 109
- (id)copyWithZone:(NSZone *)zone
110 110
{
111 -
    SPTPersistentCacheOptions * const copy = [[self.class allocWithZone:zone] init];
111 +
    SPTPersistentCacheOptions * const copy = [(SPTPersistentCacheOptions *)[self.class allocWithZone:zone] init];
112 112
113 113
    copy.cacheIdentifier = self.cacheIdentifier;
114 114
    copy.cachePath = self.cachePath;

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file
@@ -61,6 +61,13 @@
Loading
61 61
    }
62 62
}
63 63
64 +
@interface SPTPersistentCacheFileInfo : NSObject
65 +
@property (nonatomic, strong, readonly) NSString *fileName;
66 +
@property (nonatomic, strong, readonly) NSDate *mdate;
67 +
@property (nonatomic, assign, readonly) off_t fileSize;
68 +
- (instancetype)initWithFileName:(NSString *)fileName mdate:(NSDate *)mdate fileSize:(off_t)fileSize;
69 +
@end
70 +
64 71
// Class extension exists in SPTPersistentCache+Private.h
65 72
66 73
#pragma mark - SPTPersistentCache
@@ -959,22 +966,22 @@
Loading
959 966
    }
960 967
961 968
    // Find all the image names and attributes and sort oldest last
962 -
    NSMutableArray *images = [self storedImageNamesAndAttributes];
969 +
    NSMutableArray<SPTPersistentCacheFileInfo *> *files = [self storedFileNamesAndAttributes];
963 970
964 971
    // Find the free space on the disk
965 972
    SPTPersistentCacheDiskSize currentCacheSize = (SPTPersistentCacheDiskSize)[self lockedItemsSizeInBytes];
966 -
    for (NSDictionary *image in images) {
967 -
        currentCacheSize += [image[SPTDataCacheFileAttributesKey][NSFileSize] integerValue];
973 +
    for (SPTPersistentCacheFileInfo *file in files) {
974 +
        currentCacheSize += file.fileSize;
968 975
    }
969 976
970 977
    SPTPersistentCacheDiskSize optimalCacheSize = [self.dataCacheFileManager optimizedDiskSizeForCacheSize:currentCacheSize];
971 978
972 979
    // Remove oldest data until we reach acceptable cache size
973 -
    while (currentCacheSize > optimalCacheSize && images.count) {
974 -
        NSDictionary *image = images.lastObject;
975 -
        [images removeLastObject];
980 +
    while (currentCacheSize > optimalCacheSize && files.count) {
981 +
        SPTPersistentCacheFileInfo *file = files.lastObject;
982 +
        [files removeLastObject];
976 983
977 -
        NSString *fileName = image[SPTDataCacheFileNameKey];
984 +
        NSString *fileName = file.fileName;
978 985
        NSError *localError = nil;
979 986
        if (fileName.length > 0 && ![self.fileManager removeItemAtPath:fileName error:&localError]) {
980 987
            [self debugOutput:@"PersistentDataCache: %@ ERROR %@", @(__PRETTY_FUNCTION__), [localError localizedDescription]];
@@ -983,12 +990,12 @@
Loading
983 990
            [self debugOutput:@"PersistentDataCache: evicting by size key:%@", fileName.lastPathComponent];
984 991
        }
985 992
986 -
        currentCacheSize -= [image[SPTDataCacheFileAttributesKey][NSFileSize] integerValue];
993 +
        currentCacheSize -= file.fileSize;
987 994
    }
988 995
    return YES;
989 996
}
990 997
991 -
- (NSMutableArray *)storedImageNamesAndAttributes
998 +
- (NSMutableArray<SPTPersistentCacheFileInfo *> *)storedFileNamesAndAttributes
992 999
{
993 1000
    NSURL *urlPath = [NSURL fileURLWithPath:self.options.cachePath];
994 1001
@@ -1001,7 +1008,7 @@
Loading
1001 1008
                                                                errorHandler:nil];
1002 1009
1003 1010
    // An array to store the all the enumerated file names in
1004 -
    NSMutableArray *images = [NSMutableArray array];
1011 +
    NSMutableArray<SPTPersistentCacheFileInfo *> *files = [NSMutableArray array];
1005 1012
1006 1013
    // Enumerate the dirEnumerator results, each value is stored in allURLs
1007 1014
    NSURL *theURL = nil;
@@ -1043,12 +1050,12 @@
Loading
1043 1050
                 Use modification time even for files with TTL
1044 1051
                 Files with TTL have updateTime set once on creation.
1045 1052
                 */
1046 -
                NSDate *mdate = [NSDate dateWithTimeIntervalSince1970:(fileStat.st_mtimespec.tv_sec + fileStat.st_mtimespec.tv_nsec*1e9)];
1047 -
                NSNumber *fsize = [NSNumber numberWithLongLong:fileStat.st_size];
1048 -
                NSDictionary *values = @{NSFileModificationDate : mdate, NSFileSize: fsize};
1049 1053
1050 -
                [images addObject:@{ SPTDataCacheFileNameKey : filePathString,
1051 -
                                     SPTDataCacheFileAttributesKey : values }];
1054 +
                NSDate *mdate = [NSDate dateWithTimeIntervalSince1970:(fileStat.st_mtimespec.tv_sec + fileStat.st_mtimespec.tv_nsec*1e9)];
1055 +
                SPTPersistentCacheFileInfo *info = [[SPTPersistentCacheFileInfo alloc] initWithFileName:filePathString
1056 +
                                                                                                  mdate:mdate
1057 +
                                                                                               fileSize:fileStat.st_size];
1058 +
                [files addObject:info];
1052 1059
            }
1053 1060
        } else {
1054 1061
            [self debugOutput:@"Unable to fetch isDir#5 attribute:%@", theURL];
@@ -1056,15 +1063,13 @@
Loading
1056 1063
    }
1057 1064
1058 1065
    // Oldest goes last
1059 -
    NSComparisonResult(^SPTSortFilesByModificationDate)(id, id) = ^NSComparisonResult(NSDictionary *file1, NSDictionary *file2) {
1060 -
        NSDate *date1 = file1[SPTDataCacheFileAttributesKey][NSFileModificationDate];
1061 -
        NSDate *date2 = file2[SPTDataCacheFileAttributesKey][NSFileModificationDate];
1062 -
        return [date2 compare:date1];
1066 +
    NSComparisonResult(^SPTSortFilesByModificationDate)(id, id) = ^NSComparisonResult(SPTPersistentCacheFileInfo *file1, SPTPersistentCacheFileInfo *file2) {
1067 +
        return [file2.mdate compare:file1.mdate];
1063 1068
    };
1064 1069
1065 -
    NSArray *sortedImages = [images sortedArrayUsingComparator:SPTSortFilesByModificationDate];
1070 +
    [files sortUsingComparator:SPTSortFilesByModificationDate];
1066 1071
1067 -
    return [sortedImages mutableCopy];
1072 +
    return files;
1068 1073
}
1069 1074
1070 1075
- (NSTimeInterval)currentDateTimeInterval
@@ -1090,3 +1095,18 @@
Loading
1090 1095
}
1091 1096
1092 1097
@end
1098 +
1099 +
@implementation SPTPersistentCacheFileInfo
1100 +
1101 +
- (instancetype)initWithFileName:(NSString *)fileName mdate:(NSDate *)mdate fileSize:(off_t)fileSize
1102 +
{
1103 +
    self = [super init];
1104 +
    if (self) {
1105 +
        _fileName = fileName;
1106 +
        _mdate = mdate;
1107 +
        _fileSize = fileSize;
1108 +
    }
1109 +
    return self;
1110 +
}
1111 +
1112 +
@end

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file

@@ -1,5 +1,5 @@
Loading
1 1
/*
2 -
 Copyright (c) 2020 Spotify AB.
2 +
 Copyright (c) 2015-2021 Spotify AB.
3 3
4 4
 Licensed to the Apache Software Foundation (ASF) under one
5 5
 or more contributor license agreements.  See the NOTICE file
Files Coverage
Sources 97.94%
Project Totals (14 files) 97.94%
1
coverage:
2
  ignore:
3
  - Pods/.*
4
  - Applications/Xcode.app/.*
5
  - ci/.*
6
  - Carthage/.*
7
  - build/.*
8
  - Tests/.*
9
  - .*Tests.m
10
  status:
11
    patch:
12
      default:
13
        target: '80'
14
    project:
15
      default:
16
        target: auto
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading