From 73b206512aa2fde430c7a6654461845db1767fc3 Mon Sep 17 00:00:00 2001 From: Allen Cheung Date: Tue, 22 Oct 2013 14:15:42 -0700 Subject: [PATCH 1/6] option to prevent cache reads from updating entry's modification date --- TMCache/TMDiskCache.h | 6 ++++++ TMCache/TMDiskCache.m | 31 +++++++++++++++++++++++++++++-- TMCache/TMMemoryCache.h | 6 ++++++ TMCache/TMMemoryCache.m | 28 +++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 3 deletions(-) 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 From 3f0e8402bf23966dc44fe6f110342c05b236ffe9 Mon Sep 17 00:00:00 2001 From: Allen Cheung Date: Wed, 15 Jan 2014 17:08:28 -0800 Subject: [PATCH 2/6] Fixing a bug with reading a file URL when updateEntryDateOnRead is set to NO --- TMCache/TMDiskCache.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TMCache/TMDiskCache.m b/TMCache/TMDiskCache.m index 95f526a..0c14c8f 100644 --- a/TMCache/TMDiskCache.m +++ b/TMCache/TMDiskCache.m @@ -428,7 +428,8 @@ - (void)fileURLForKey:(NSString *)key block:(TMDiskCacheObjectBlock)block NSURL *fileURL = [strongSelf encodedFileURLForKey:key]; - if ([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]] && _updateEntryDateOnRead) { + if ([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) { + if (_updateEntryDateOnRead) [strongSelf setFileModificationDate:now forURL:fileURL]; } else { fileURL = nil; From 71fdc30d9850dc0ef7a6b725668128f3773b91be Mon Sep 17 00:00:00 2001 From: Allen Cheung Date: Fri, 20 Jun 2014 11:23:44 -0700 Subject: [PATCH 3/6] Changing podspec for Yelp fork --- TMCache.podspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TMCache.podspec b/TMCache.podspec index 480ef0d..c3525bd 100644 --- a/TMCache.podspec +++ b/TMCache.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| - s.name = 'TMCache' + s.name = 'TMCacheYelpFork' 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.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/tumblr/TMCache.git', :tag => "#{s.version}" } + s.source = { :git => 'https://github.com/Yelp/TMCache.git', :tag => "#{s.version}" } s.license = { :type => 'Apache 2.0', :file => 'LICENSE.txt' } s.requires_arc = true s.frameworks = 'Foundation' From 7aa750de9efa882f95146596a851bb3ed498e2b9 Mon Sep 17 00:00:00 2001 From: Allen Cheung Date: Fri, 20 Jun 2014 12:03:51 -0700 Subject: [PATCH 4/6] Renaming podspec to name for Yelp fork --- TMCache.podspec => TMCacheYelpFork.podspec | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TMCache.podspec => TMCacheYelpFork.podspec (100%) diff --git a/TMCache.podspec b/TMCacheYelpFork.podspec similarity index 100% rename from TMCache.podspec rename to TMCacheYelpFork.podspec From 0e96623f51ca4688d6ba2c9176846931f249431f Mon Sep 17 00:00:00 2001 From: Mason Glidden Date: Fri, 18 Jul 2014 14:06:25 -0700 Subject: [PATCH 5/6] Updating podspec --- TMCacheYelpFork.podspec | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TMCacheYelpFork.podspec b/TMCacheYelpFork.podspec index c3525bd..fb75363 100644 --- a/TMCacheYelpFork.podspec +++ b/TMCacheYelpFork.podspec @@ -1,12 +1,13 @@ Pod::Spec.new do |s| s.name = 'TMCacheYelpFork' - s.version = '1.2.0' + s.version = '1.2.1' 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 => "#{s.version}" } + s.source = { :git => 'https://github.com/Yelp/TMCache.git', :tag => "v#{s.version}" } 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' From cae6f417af05af72dbc2ae73cb7a8f7af6aa455d Mon Sep 17 00:00:00 2001 From: Mason Glidden Date: Thu, 31 Jul 2014 10:24:38 -0700 Subject: [PATCH 6/6] Removed documentation parameter from podspec. --- TMCacheYelpFork.podspec | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/TMCacheYelpFork.podspec b/TMCacheYelpFork.podspec index fb75363..57aeb4c 100644 --- a/TMCacheYelpFork.podspec +++ b/TMCacheYelpFork.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = 'TMCacheYelpFork' - s.version = '1.2.1' + 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}" } + 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 @@ -14,23 +14,4 @@ Pod::Spec.new do |s| 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