Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added copyFilePath:asKey:

  • Loading branch information...
commit 8865cbaa0517be4e680236fa27c0111f44021078 1 parent 7dfcb95
@shnhrrsn shnhrrsn authored
Showing with 21 additions and 5 deletions.
  1. +8 −5 EGOCache.h
  2. +13 −0 EGOCache.m
View
13 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
View
13 EGOCache.m
@@ -128,6 +128,19 @@ - (BOOL)hasCacheForKey:(NSString*)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
- (void)setData:(NSData*)data forKey:(NSString*)key {
Please sign in to comment.
Something went wrong with that request. Please try again.