Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions TMCache.podspec

This file was deleted.

6 changes: 6 additions & 0 deletions TMCache/TMDiskCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ typedef void (^TMDiskCacheObjectBlock)(TMDiskCache *cache, NSString *key, id <NS
*/
@property (assign) NSTimeInterval ageLimit;

/**
A flag that determines whether reading from the cache should update the entry's modification
date. Cache objects become stale if they haven't been overwritten wihtin the age limit. Default is YES.
*/
@property (assign) BOOL updateEntryDateOnRead;

#pragma mark -
/// @name Event Blocks

Expand Down
30 changes: 29 additions & 1 deletion TMCache/TMDiskCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @implementation TMDiskCache
@synthesize didRemoveAllObjectsBlock = _didRemoveAllObjectsBlock;
@synthesize byteLimit = _byteLimit;
@synthesize ageLimit = _ageLimit;
@synthesize updateEntryDateOnRead = _updateEntryDateOnRead;

#pragma mark - Initialization -

Expand All @@ -57,6 +58,7 @@ - (instancetype)initWithName:(NSString *)name
_byteCount = 0;
_byteLimit = 0;
_ageLimit = 0.0;
_updateEntryDateOnRead = YES;

_dates = [[NSMutableDictionary alloc] init];
_sizes = [[NSMutableDictionary alloc] init];
Expand Down Expand Up @@ -402,7 +404,8 @@ - (void)objectForKey:(NSString *)key block:(TMDiskCacheObjectBlock)block

if ([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
object = [NSKeyedUnarchiver unarchiveObjectWithFile:[fileURL path]];
[strongSelf setFileModificationDate:now forURL:fileURL];
if (_updateEntryDateOnRead)
[strongSelf setFileModificationDate:now forURL:fileURL];
}

block(strongSelf, key, object, fileURL);
Expand All @@ -426,6 +429,7 @@ - (void)fileURLForKey:(NSString *)key block:(TMDiskCacheObjectBlock)block
NSURL *fileURL = [strongSelf encodedFileURLForKey:key];

if ([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
if (_updateEntryDateOnRead)
[strongSelf setFileModificationDate:now forURL:fileURL];
} else {
fileURL = nil;
Expand Down Expand Up @@ -1033,4 +1037,28 @@ - (void)setAgeLimit:(NSTimeInterval)ageLimit
});
}

- (BOOL)updateEntryDateOnRead
{
__block BOOL updateEntryDateOnRead = NO;

dispatch_sync(_queue, ^{
updateEntryDateOnRead = _updateEntryDateOnRead;
});

return updateEntryDateOnRead;
}

- (void)setUpdateEntryDateOnRead:(BOOL)updateEntryDateOnRead
{
__weak TMDiskCache *weakSelf = self;

dispatch_barrier_async(_queue, ^{
TMDiskCache *strongSelf = weakSelf;
if (!strongSelf)
return;

strongSelf->_updateEntryDateOnRead = updateEntryDateOnRead;
});
}

@end
6 changes: 6 additions & 0 deletions TMCache/TMMemoryCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ typedef void (^TMMemoryCacheObjectBlock)(TMMemoryCache *cache, NSString *key, id
*/
@property (assign) NSTimeInterval ageLimit;

/**
A flag that determines whether reading from the cache should update the entry's modification
date. Cache objects become stale if they haven't been overwritten wihtin the age limit. Default is YES.
*/
@property (assign) BOOL updateEntryDateOnRead;

/**
When `YES` on iOS the cache will remove all objects when the app receives a memory warning.
Defaults to `YES`.
Expand Down
28 changes: 27 additions & 1 deletion TMCache/TMMemoryCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @implementation TMMemoryCache
@synthesize ageLimit = _ageLimit;
@synthesize costLimit = _costLimit;
@synthesize totalCost = _totalCost;
@synthesize updateEntryDateOnRead = _updateEntryDateOnRead;
@synthesize willAddObjectBlock = _willAddObjectBlock;
@synthesize willRemoveObjectBlock = _willRemoveObjectBlock;
@synthesize willRemoveAllObjectsBlock = _willRemoveAllObjectsBlock;
Expand Down Expand Up @@ -63,6 +64,7 @@ - (id)init
_ageLimit = 0.0;
_costLimit = 0;
_totalCost = 0;
_updateEntryDateOnRead = YES;

_removeAllObjectsOnMemoryWarning = YES;
_removeAllObjectsOnEnteringBackground = YES;
Expand Down Expand Up @@ -243,7 +245,7 @@ - (void)objectForKey:(NSString *)key block:(TMMemoryCacheObjectBlock)block
__weak TMMemoryCache *weakSelf = strongSelf;
dispatch_barrier_async(strongSelf->_queue, ^{
TMMemoryCache *strongSelf = weakSelf;
if (strongSelf)
if (strongSelf && _updateEntryDateOnRead)
[strongSelf->_dates setObject:now forKey:key];
});
}
Expand Down Expand Up @@ -867,4 +869,28 @@ - (NSUInteger)totalCost
return cost;
}

- (BOOL)updateEntryDateOnRead
{
__block BOOL updateEntryDateOnRead = NO;

dispatch_sync(_queue, ^{
updateEntryDateOnRead = _updateEntryDateOnRead;
});

return updateEntryDateOnRead;
}

- (void)setUpdateEntryDateOnRead:(BOOL)updateEntryDateOnRead
{
__weak TMMemoryCache *weakSelf = self;

dispatch_barrier_async(_queue, ^{
TMMemoryCache *strongSelf = weakSelf;
if (!strongSelf)
return;

strongSelf->_updateEntryDateOnRead = updateEntryDateOnRead;
});
}

@end
17 changes: 17 additions & 0 deletions TMCacheYelpFork.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Pod::Spec.new do |s|
s.name = 'TMCacheYelpFork'
s.version = '1.2.2'
s.source_files = 'TMCache/*.{h,m}'
s.homepage = 'https://github.com/Yelp/TMCache'
s.summary = 'Fast parallel object cache for iOS and OS X. Yelp fork.'
s.authors = { 'Justin Ouellette' => 'jstn@tumblr.com' }
s.source = { :git => 'https://github.com/Yelp/TMCache.git', :tag => 'v' + s.version.to_s }
s.license = { :type => 'Apache 2.0', :file => 'LICENSE.txt' }
s.header_dir = 'TMCache'
s.requires_arc = true
s.frameworks = 'Foundation'
s.ios.weak_frameworks = 'UIKit'
s.osx.weak_frameworks = 'AppKit'
s.ios.deployment_target = '5.0'
s.osx.deployment_target = '10.7'
end