From 8865cbaa0517be4e680236fa27c0111f44021078 Mon Sep 17 00:00:00 2001 From: shnhrrsn Date: Wed, 6 Jan 2010 10:07:14 -0500 Subject: [PATCH] Added copyFilePath:asKey: --- EGOCache.h | 13 ++++++++----- EGOCache.m | 13 +++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/EGOCache.h b/EGOCache.h index 9f50a78..5ecee96 100644 --- a/EGOCache.h +++ b/EGOCache.h @@ -28,26 +28,29 @@ - (BOOL)hasCacheForKey:(NSString*)key; - (NSData*)dataForKey:(NSString*)key; -- (void)setData:(NSData*)data forKey:(NSString*)key; // withTimeoutInterval:defaultTimeoutInterval +- (void)setData:(NSData*)data forKey:(NSString*)key; - (void)setData:(NSData*)data forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; - (NSString*)stringForKey:(NSString*)key; -- (void)setString:(NSString*)aString forKey:(NSString*)key; // withTimeoutInterval:defaultTimeoutInterval +- (void)setString:(NSString*)aString forKey:(NSString*)key; - (void)setString:(NSString*)aString forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; #if TARGET_OS_IPHONE - (UIImage*)imageForKey:(NSString*)key; -- (void)setImage:(UIImage*)anImage forKey:(NSString*)key; // withTimeoutInterval:defaultTimeoutInterval +- (void)setImage:(UIImage*)anImage forKey:(NSString*)key; - (void)setImage:(UIImage*)anImage forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; #else - (NSImage*)imageForKey:(NSString*)key; -- (void)setImage:(NSImage*)anImage forKey:(NSString*)key; // withTimeoutInterval:defaultTimeoutInterval +- (void)setImage:(NSImage*)anImage forKey:(NSString*)key; - (void)setImage:(NSImage*)anImage forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; #endif - (NSData*)plistForKey:(NSString*)key; -- (void)setPlist:(id)plistObject forKey:(NSString*)key; // withTimeoutInterval:defaultTimeoutInterval +- (void)setPlist:(id)plistObject forKey:(NSString*)key; - (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; +- (void)copyFilePath:(NSString*)filePath asKey:(NSString*)key; +- (void)copyFilePath:(NSString*)filePath asKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; + @property(nonatomic,assign) NSTimeInterval defaultTimeoutInterval; // Default is 1 day @end \ No newline at end of file diff --git a/EGOCache.m b/EGOCache.m index 0429003..d010e1a 100644 --- a/EGOCache.m +++ b/EGOCache.m @@ -127,6 +127,19 @@ - (BOOL)hasCacheForKey:(NSString*)key { return [[NSFileManager defaultManager] fileExistsAtPath:cachePathForKey(key)]; } +#pragma mark - +#pragma mark Copy file methods + +- (void)copyFilePath:(NSString*)filePath asKey:(NSString*)key { + [self copyFilePath:filePath asKey:key withTimeoutInterval:self.defaultTimeoutInterval]; +} + +- (void)copyFilePath:(NSString*)filePath asKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval { + [[NSFileManager defaultManager] copyItemAtPath:filePath toPath:cachePathForKey(key) error:NULL]; + [cacheDictionary setObject:[NSDate dateWithTimeIntervalSinceNow:timeoutInterval] forKey:key]; + [self performSelectorOnMainThread:@selector(saveAfterDelay) withObject:nil waitUntilDone:YES]; +} + #pragma mark - #pragma mark Data methods