Permalink
Browse files

Merge branch 'master' of git://gist.github.com/243496

  • Loading branch information...
2 parents 243109a + 03484b3 commit c3fefe23db09be822b61d0fd62bfdaa310c5c013 @shnhrrsn shnhrrsn committed Nov 26, 2009
Showing with 44 additions and 0 deletions.
  1. +9 −0 EGOCache+Plist.h
  2. +35 −0 EGOCache+Plist.m
View
9 EGOCache+Plist.h
@@ -0,0 +1,9 @@
+#import "EGOCache.h"
+
+@interface EGOCache (Plist)
+
+- (NSData*)plistForKey:(NSString*)key;
+- (void)setPlist:(id)plistObject forKey:(NSString*)key;
+- (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
+
+@end
View
35 EGOCache+Plist.m
@@ -0,0 +1,35 @@
+#import "EGOCache.h"
+#import "EGOCache+Plist.h"
+
+@implementation EGOCache (Plist)
+
+- (NSData*)plistForKey:(NSString*)key;
+{
+ NSData *plistData = [self dataForKey:key];
+ return [NSPropertyListSerialization
+ propertyListFromData:plistData
+ mutabilityOption:NSPropertyListImmutable
+ format:nil
+ errorDescription:nil];
+}
+
+- (void)setPlist:(id)plistObject forKey:(NSString*)key;
+{
+ [self setPlist:plistObject forKey:key withTimeoutInterval:60 * 60 * 24];
+}
+
+// XML format would produce cache files that are human-readable but at the
+// expense of performance, so I felt binary format was best.
+
+- (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
+{
+ NSString *errorString;
+ NSData *plistData = [NSPropertyListSerialization
+ dataFromPropertyList:plistObject
+ format:NSPropertyListBinaryFormat_v1_0
+ errorDescription:&errorString];
+
+ [self setData:plistData forKey:key withTimeoutInterval:timeoutInterval];
+}
+
+@end

0 comments on commit c3fefe2

Please sign in to comment.