Skip to content

Commit d406ba6

Browse files
committed
Merge commit 'df60b0d9c1903ca4cdb1e928b04ea1203aa28ad2'
* commit 'df60b0d9c1903ca4cdb1e928b04ea1203aa28ad2': Support Catalyst (pinterest#272) Fix the grammar in an assertion failure message (pinterest#270) Remove the unused CI directory (pinterest#265) Fix up analyze for github CI (pinterest#264) Check fileURL outside of the locked scope (pinterest#262) Optimization `PINMemoryCache` trim to date (pinterest#252) Use correct class name in NSAssert() messages (pinterest#263) Remove Danger from the project (pinterest#261) Link to master branch workflow from the CI badge Test that the "remove object" blocks are called (pinterest#258) Fix GitHub Actions CI badge Switch to GitHub Actions for CI (pinterest#259) Discrepancy between Header Comment and Implementation (pinterest#257) # Conflicts: # Makefile # PINCache.xcodeproj/project.pbxproj # Tests/PINCacheTests.m
2 parents 76f4d67 + df60b0d commit d406ba6

File tree

8 files changed

+2632
-20
lines changed

8 files changed

+2632
-20
lines changed

.github/workflows/ci.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: CI
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
- 'releases/*'
9+
pull_request:
10+
branches:
11+
- master
12+
13+
jobs:
14+
build:
15+
name: Build
16+
runs-on: macOS-latest
17+
strategy:
18+
matrix:
19+
platform: ['iOS Simulator,name=iPhone 8']
20+
steps:
21+
- uses: actions/checkout@v1
22+
- name: Analyze and Test
23+
run: |
24+
xcodebuild clean analyze test \
25+
-destination "platform=${{ matrix.platform }}" \
26+
-sdk "iphonesimulator" \
27+
-project PINCache.xcodeproj \
28+
-scheme PINCache \
29+
ONLY_ACTIVE_ARCH=NO \
30+
CODE_SIGNING_REQUIRED=NO \
31+
CLANG_ANALYZER_OUTPUT=plist-html \
32+
CLANG_ANALYZER_OUTPUT_DIR="$(pwd)/clang" \
33+
| xcpretty
34+
if [[ -n `find $(pwd)/clang -name "*.html"` ]] ; then rm -rf $(pwd)/clang; exit 1; fi
35+
rm -rf $(pwd)/clang
36+
cocoapods:
37+
name: CocoaPods
38+
runs-on: macOS-latest
39+
steps:
40+
- uses: actions/checkout@v1
41+
- name: Lint
42+
run: pod lib lint
43+
carthage:
44+
name: Carthage
45+
runs-on: macOS-latest
46+
steps:
47+
- uses: actions/checkout@v1
48+
- name: Update
49+
run: carthage update --no-use-binaries --no-build
50+
- name: Build
51+
run: carthage build --no-skip-current

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
* Add your own contributions to the next release on the line below this with your name.
44

5+
- [performance] Optimization `PINMemoryCache` trim to date. [#252](https://github.com/pinterest/PINCache/pull/252)
56
- [performance] Optimize `PINMemoryCache` remove objects when receive memory warning notification. [#251](https://github.com/pinterest/PINCache/pull/251)
7+
- [new] Migrated to GitHub Actions for continuous integration. [#259](https://github.com/pinterest/PINCache/pull/259)
68

79
## 3.0.1 -- Beta 8
810
- [fix] Initing PINCache with TTL enabled should enable TTL on PINMemoryCache. [#246](https://github.com/pinterest/PINCache/pull/246)

PINCache.xcodeproj/project.pbxproj

+1,157
Large diffs are not rendered by default.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![CocoaPods](https://img.shields.io/cocoapods/v/PINCache.svg)](http://cocoadocs.org/docsets/PINCache/)
44
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
5-
[![Build status](https://badge.buildkite.com/03e247305c96c3371f2ff2766e9c8c1efdd5fdb3a7eceaff43.svg?branch=master&style=flat)](https://buildkite.com/pinterest/pincache)
5+
[![Build status](https://github.com/pinterest/PINCache/workflows/CI/badge.svg)](https://github.com/pinterest/PINCache/actions?query=workflow%3ACI+branch%3Amaster)
66

77
## Fast, non-deadlocking parallel object cache for iOS and OS X.
88

Source/PINDiskCache.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger, PINDiskCacheError) {
2626
/**
2727
A callback block which provides the cache, key and object as arguments
2828
*/
29-
typedef void (^PINDiskCacheObjectBlock)(PINDiskCache *cache, NSString *key, id <NSCoding> _Nullable object);
29+
typedef void (^PINDiskCacheObjectBlock)(PINDiskCache *cache, NSString *key, id <NSCoding> _Nullable object);
3030

3131
/**
3232
A callback block which provides the key and fileURL of the object
@@ -155,15 +155,15 @@ PIN_SUBCLASSING_RESTRICTED
155155

156156
/**
157157
The maximum number of bytes allowed on disk. This value is checked every time an object is set, if the written
158-
size exceeds the limit a trim call is queued. Defaults to `0.0`, meaning no practical limit.
158+
size exceeds the limit a trim call is queued. Defaults to 50MB.
159159
160160
*/
161161
@property (assign) NSUInteger byteLimit;
162162

163163
/**
164164
The maximum number of seconds an object is allowed to exist in the cache. Setting this to a value
165165
greater than `0.0` will start a recurring GCD timer with the same period that calls <trimToDate:>.
166-
Setting it back to `0.0` will stop the timer. Defaults to `0.0`, meaning no limit.
166+
Setting it back to `0.0` will stop the timer. Defaults to 30 days.
167167
168168
*/
169169
@property (assign) NSTimeInterval ageLimit;

Source/PINDiskCache.m

+10-7
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ @implementation PINDiskCache
111111
- (void)dealloc
112112
{
113113
__unused int result = pthread_mutex_destroy(&_mutex);
114-
NSCAssert(result == 0, @"Failed to destroy lock in PINMemoryCache %p. Code: %d", (void *)self, result);
114+
NSCAssert(result == 0, @"Failed to destroy lock in PINDiskCache %p. Code: %d", (void *)self, result);
115115
pthread_cond_destroy(&_diskWritableCondition);
116116
pthread_cond_destroy(&_diskStateKnownCondition);
117117
}
@@ -185,19 +185,19 @@ - (instancetype)initWithName:(NSString *)name
185185
operationQueue:(PINOperationQueue *)operationQueue
186186
ttlCache:(BOOL)ttlCache
187187
{
188-
if (!name)
188+
if (!name) {
189189
return nil;
190-
190+
}
191191

192192
NSAssert(((!serializer && !deserializer) || (serializer && deserializer)),
193193
@"PINDiskCache must be initialized with a serializer AND deserializer.");
194194

195195
NSAssert(((!keyEncoder && !keyDecoder) || (keyEncoder && keyDecoder)),
196-
@"PINDiskCache must be initialized with a encoder AND decoder.");
196+
@"PINDiskCache must be initialized with an encoder AND decoder.");
197197

198198
if (self = [super init]) {
199199
__unused int result = pthread_mutex_init(&_mutex, NULL);
200-
NSAssert(result == 0, @"Failed to init lock in PINMemoryCache %@. Code: %d", self, result);
200+
NSAssert(result == 0, @"Failed to init lock in PINDiskCache %@. Code: %d", self, result);
201201

202202
_name = [name copy];
203203
_prefix = [prefix copy];
@@ -666,10 +666,13 @@ - (BOOL)_locked_setAgeLimit:(NSTimeInterval)ageLimit forURL:(NSURL *)fileURL
666666
- (BOOL)removeFileAndExecuteBlocksForKey:(NSString *)key
667667
{
668668
NSURL *fileURL = [self encodedFileURLForKey:key];
669-
669+
if (!fileURL) {
670+
return NO;
671+
}
672+
670673
// We only need to lock until writable at the top because once writable, always writable
671674
[self lockForWriting];
672-
if (!fileURL || ![[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
675+
if (![[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
673676
[self unlock];
674677
return NO;
675678
}

Source/PINMemoryCache.m

+5-9
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,19 @@ - (void)removeObjectAndExecuteBlocksForKey:(NSString *)key
191191
- (void)trimMemoryToDate:(NSDate *)trimDate
192192
{
193193
[self lock];
194-
NSArray *keysSortedByCreatedDate = [_createdDates keysSortedByValueUsingSelector:@selector(compare:)];
195194
NSDictionary *createdDates = [_createdDates copy];
196195
NSDictionary *ageLimits = [_ageLimits copy];
197196
[self unlock];
198197

199-
for (NSString *key in keysSortedByCreatedDate) { // oldest objects first
200-
NSDate *createdDate = createdDates[key];
198+
[createdDates enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSDate * _Nonnull createdDate, BOOL * _Nonnull stop) {
201199
NSTimeInterval ageLimit = [ageLimits[key] doubleValue];
202-
if (!createdDate || ageLimit > 0.0)
203-
continue;
204-
200+
if (!createdDate || ageLimit > 0.0) {
201+
return;
202+
}
205203
if ([createdDate compare:trimDate] == NSOrderedAscending) { // older than trim date
206204
[self removeObjectAndExecuteBlocksForKey:key];
207-
} else {
208-
break;
209205
}
210-
}
206+
}];
211207
}
212208

213209
- (void)removeExpiredObjects

0 commit comments

Comments
 (0)