diff --git a/TMCache.podspec b/TMCache.podspec deleted file mode 100644 index 480ef0d..0000000 --- a/TMCache.podspec +++ /dev/null @@ -1,35 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'TMCache' - s.version = '1.2.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.' - s.authors = { 'Justin Ouellette' => 'jstn@tumblr.com' } - s.source = { :git => 'https://github.com/tumblr/TMCache.git', :tag => "#{s.version}" } - s.license = { :type => 'Apache 2.0', :file => 'LICENSE.txt' } - 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' - s.documentation = { - :html => 'http://cocoadocs.org/docsets/TMCache/', - :appledoc => [ - '--company-id', 'com.tumblr', - '--project-name', 'TMCache', - '--project-company', 'Tumblr', - '--project-version', '1.2.0', - '--docset-min-xcode-version', '4.3', - '--docset-bundle-name', '%PROJECT %VERSION', - '--docset-bundle-id', '%COMPANYID.%PROJECTID', - '--docset-bundle-filename', '%COMPANYID.%PROJECTID-%VERSIONID.docset', - '--ignore', 'tests', - '--ignore', 'docs', - '--ignore', '*.m', - '--no-repeat-first-par', - '--explicit-crossref', - '--clean-output' - ] - } -end diff --git a/TMCache/TMDiskCache.h b/TMCache/TMDiskCache.h index e62a728..d39d09f 100644 --- a/TMCache/TMDiskCache.h +++ b/TMCache/TMDiskCache.h @@ -79,6 +79,12 @@ typedef void (^TMDiskCacheObjectBlock)(TMDiskCache *cache, NSString *key, id _updateEntryDateOnRead = updateEntryDateOnRead; + }); +} + @end diff --git a/TMCache/TMMemoryCache.h b/TMCache/TMMemoryCache.h index 1e6a291..62e475d 100644 --- a/TMCache/TMMemoryCache.h +++ b/TMCache/TMMemoryCache.h @@ -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`. diff --git a/TMCache/TMMemoryCache.m b/TMCache/TMMemoryCache.m index 66972cc..5bd85de 100644 --- a/TMCache/TMMemoryCache.m +++ b/TMCache/TMMemoryCache.m @@ -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; @@ -63,6 +64,7 @@ - (id)init _ageLimit = 0.0; _costLimit = 0; _totalCost = 0; + _updateEntryDateOnRead = YES; _removeAllObjectsOnMemoryWarning = YES; _removeAllObjectsOnEnteringBackground = YES; @@ -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]; }); } @@ -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 diff --git a/TMCacheYelpFork.podspec b/TMCacheYelpFork.podspec new file mode 100644 index 0000000..57aeb4c --- /dev/null +++ b/TMCacheYelpFork.podspec @@ -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