Skip to content

Commit

Permalink
Merge pull request #86 from tumblr/feature/add-back-notification-obse…
Browse files Browse the repository at this point in the history
…rvation

Add back notification observation that was stupidly removed in 2.0.0
  • Loading branch information
irace committed May 8, 2015
2 parents 94a3d3e + c37dfb6 commit ed74c6f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 2.1 -- 2015 May 8 ###

Removes the need for the explicit memory warning and application background handling, which was an ill-advised change in 2.0.

The other part of the 2.0 release still applies; you need to explicitly provide an object that knows how to vend background tasks in order for operations to continue after your application has been backgrounded.

### 2.0.0 -- 2015 April 27 ###

2.0.0 removes all references to `UIApplication sharedApplication`. As of iOS 8, this method is annotated with `NS_EXTENSION_UNAVAILABLE_IOS`, meaning that it won’t compile as part of an iOS 8 extension. In order to facilitate `TMCache` usage inside extensions.
Expand Down
2 changes: 1 addition & 1 deletion TMCache.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TMCache'
s.version = '2.0.0'
s.version = '2.1.0'
s.source_files = 'TMCache/*.{h,m}'
s.homepage = 'https://github.com/tumblr/TMCache'
s.summary = 'Fast parallel object cache for iOS and OS X.'
Expand Down
10 changes: 8 additions & 2 deletions TMCache/TMMemoryCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,14 @@ typedef void (^TMMemoryCacheObjectBlock)(TMMemoryCache *cache, NSString *key, id
*/
- (void)enumerateObjectsWithBlock:(TMMemoryCacheObjectBlock)block;

- (void)handleMemoryWarning;
/**
Handle a memory warning.
*/
- (void)handleMemoryWarning __deprecated_msg("This happens automatically in TMCache 2.1. There’s no longer a need to call it directly.");

- (void)handleApplicationBackgrounding;
/**
Handle the application having been backgrounded.
*/
- (void)handleApplicationBackgrounding __deprecated_msg("This happens automatically in TMCache 2.1. There’s no longer a need to call it directly.");

@end
28 changes: 21 additions & 7 deletions TMCache/TMMemoryCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ - (id)init

_removeAllObjectsOnMemoryWarning = YES;
_removeAllObjectsOnEnteringBackground = YES;

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMemoryWarning)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleApplicationBackgrounding)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
#endif
}
return self;
}
Expand All @@ -88,9 +100,10 @@ + (instancetype)sharedCache

#pragma mark - Private Methods -

- (void)handleMemoryWarning {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0

- (void)handleMemoryWarning
{
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0

if (self.removeAllObjectsOnMemoryWarning)
[self removeAllObjects:nil];

Expand All @@ -105,11 +118,12 @@ - (void)handleMemoryWarning {
strongSelf->_didReceiveMemoryWarningBlock(strongSelf);
});

#endif
#endif
}

- (void)handleApplicationBackgrounding {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
- (void)handleApplicationBackgrounding
{
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0

if (self.removeAllObjectsOnEnteringBackground)
[self removeAllObjects:nil];
Expand All @@ -125,7 +139,7 @@ - (void)handleApplicationBackgrounding {
strongSelf->_didEnterBackgroundBlock(strongSelf);
});

#endif
#endif
}

- (void)removeObjectAndExecuteBlocksForKey:(NSString *)key
Expand Down

0 comments on commit ed74c6f

Please sign in to comment.