From 8ad8111a3f9b8aac1d3358540a855ff8b9c52253 Mon Sep 17 00:00:00 2001 From: Andy Finnell Date: Fri, 10 May 2024 18:27:51 -0400 Subject: [PATCH] Add ability to configure maxConcurrentOperations (#329) * Add ability to configure maxConcurrentOperations ## Summary PINCache uses a PINOperationQueue to perform async operations on a background queue, while preventing thread explosion. However, the amount is hardcoded to 10 and I'd like to be able to experiment with how much concurrency we use. Therefore, add a property to allow it to be configuration. ## Testing Since it's just a configuration parameter, make sure the unit tests still pass. * Only PINCache implements the property so move it there instead of the protocol * Nudge github actions --- Source/PINCache.h | 5 +++++ Source/PINCache.m | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/Source/PINCache.h b/Source/PINCache.h index 9868c3d..80782ec 100644 --- a/Source/PINCache.h +++ b/Source/PINCache.h @@ -42,6 +42,11 @@ PIN_SUBCLASSING_RESTRICTED */ @property (readonly) NSUInteger diskByteCount; +/** + Sets/gets the maximum number of concurrent operations when handling async requests. + */ +@property (nonatomic) NSUInteger maxConcurrentOperations; + /** The underlying disk cache, see for additional configuration and trimming options. */ diff --git a/Source/PINCache.m b/Source/PINCache.m index 1ad02ee..5666e85 100644 --- a/Source/PINCache.m +++ b/Source/PINCache.m @@ -389,6 +389,16 @@ - (void)removeAllObjects [_diskCache removeAllObjects]; } +- (NSUInteger)maxConcurrentOperations +{ + return _operationQueue.maxConcurrentOperations; +} + +- (void)setMaxConcurrentOperations:(NSUInteger)maxOperations +{ + _operationQueue.maxConcurrentOperations = maxOperations; +} + @end @implementation PINCache (Deprecated)