Skip to content

Commit

Permalink
Merge commit 'df60b0d9c1903ca4cdb1e928b04ea1203aa28ad2'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adlerj-hs committed Aug 4, 2020
2 parents 76f4d67 + df60b0d commit d406ba6
Show file tree
Hide file tree
Showing 8 changed files with 2,632 additions and 20 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yaml
@@ -0,0 +1,51 @@
---
name: CI

on:
push:
branches:
- master
- 'releases/*'
pull_request:
branches:
- master

jobs:
build:
name: Build
runs-on: macOS-latest
strategy:
matrix:
platform: ['iOS Simulator,name=iPhone 8']
steps:
- uses: actions/checkout@v1
- name: Analyze and Test
run: |
xcodebuild clean analyze test \
-destination "platform=${{ matrix.platform }}" \
-sdk "iphonesimulator" \
-project PINCache.xcodeproj \
-scheme PINCache \
ONLY_ACTIVE_ARCH=NO \
CODE_SIGNING_REQUIRED=NO \
CLANG_ANALYZER_OUTPUT=plist-html \
CLANG_ANALYZER_OUTPUT_DIR="$(pwd)/clang" \
| xcpretty
if [[ -n `find $(pwd)/clang -name "*.html"` ]] ; then rm -rf $(pwd)/clang; exit 1; fi
rm -rf $(pwd)/clang
cocoapods:
name: CocoaPods
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- name: Lint
run: pod lib lint
carthage:
name: Carthage
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- name: Update
run: carthage update --no-use-binaries --no-build
- name: Build
run: carthage build --no-skip-current
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,7 +2,9 @@

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

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

## 3.0.1 -- Beta 8
- [fix] Initing PINCache with TTL enabled should enable TTL on PINMemoryCache. [#246](https://github.com/pinterest/PINCache/pull/246)
Expand Down
1,157 changes: 1,157 additions & 0 deletions PINCache.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@

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

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

Expand Down
6 changes: 3 additions & 3 deletions Source/PINDiskCache.h
Expand Up @@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger, PINDiskCacheError) {
/**
A callback block which provides the cache, key and object as arguments
*/
typedef void (^PINDiskCacheObjectBlock)(PINDiskCache *cache, NSString *key, id <NSCoding> _Nullable object);
typedef void (^PINDiskCacheObjectBlock)(PINDiskCache *cache, NSString *key, id <NSCoding> _Nullable object);

/**
A callback block which provides the key and fileURL of the object
Expand Down Expand Up @@ -155,15 +155,15 @@ PIN_SUBCLASSING_RESTRICTED

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

/**
The maximum number of seconds an object is allowed to exist in the cache. Setting this to a value
greater than `0.0` will start a recurring GCD timer with the same period that calls <trimToDate:>.
Setting it back to `0.0` will stop the timer. Defaults to `0.0`, meaning no limit.
Setting it back to `0.0` will stop the timer. Defaults to 30 days.
*/
@property (assign) NSTimeInterval ageLimit;
Expand Down
17 changes: 10 additions & 7 deletions Source/PINDiskCache.m
Expand Up @@ -111,7 +111,7 @@ @implementation PINDiskCache
- (void)dealloc
{
__unused int result = pthread_mutex_destroy(&_mutex);
NSCAssert(result == 0, @"Failed to destroy lock in PINMemoryCache %p. Code: %d", (void *)self, result);
NSCAssert(result == 0, @"Failed to destroy lock in PINDiskCache %p. Code: %d", (void *)self, result);
pthread_cond_destroy(&_diskWritableCondition);
pthread_cond_destroy(&_diskStateKnownCondition);
}
Expand Down Expand Up @@ -185,19 +185,19 @@ - (instancetype)initWithName:(NSString *)name
operationQueue:(PINOperationQueue *)operationQueue
ttlCache:(BOOL)ttlCache
{
if (!name)
if (!name) {
return nil;

}

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

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

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

_name = [name copy];
_prefix = [prefix copy];
Expand Down Expand Up @@ -666,10 +666,13 @@ - (BOOL)_locked_setAgeLimit:(NSTimeInterval)ageLimit forURL:(NSURL *)fileURL
- (BOOL)removeFileAndExecuteBlocksForKey:(NSString *)key
{
NSURL *fileURL = [self encodedFileURLForKey:key];

if (!fileURL) {
return NO;
}

// We only need to lock until writable at the top because once writable, always writable
[self lockForWriting];
if (!fileURL || ![[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
if (![[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
[self unlock];
return NO;
}
Expand Down
14 changes: 5 additions & 9 deletions Source/PINMemoryCache.m
Expand Up @@ -191,23 +191,19 @@ - (void)removeObjectAndExecuteBlocksForKey:(NSString *)key
- (void)trimMemoryToDate:(NSDate *)trimDate
{
[self lock];
NSArray *keysSortedByCreatedDate = [_createdDates keysSortedByValueUsingSelector:@selector(compare:)];
NSDictionary *createdDates = [_createdDates copy];
NSDictionary *ageLimits = [_ageLimits copy];
[self unlock];

for (NSString *key in keysSortedByCreatedDate) { // oldest objects first
NSDate *createdDate = createdDates[key];
[createdDates enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSDate * _Nonnull createdDate, BOOL * _Nonnull stop) {
NSTimeInterval ageLimit = [ageLimits[key] doubleValue];
if (!createdDate || ageLimit > 0.0)
continue;

if (!createdDate || ageLimit > 0.0) {
return;
}
if ([createdDate compare:trimDate] == NSOrderedAscending) { // older than trim date
[self removeObjectAndExecuteBlocksForKey:key];
} else {
break;
}
}
}];
}

- (void)removeExpiredObjects
Expand Down

0 comments on commit d406ba6

Please sign in to comment.