-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCache.m
44 lines (38 loc) · 1.19 KB
/
Cache.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Cache.m
// MisoUIV3
//
// Created by HEENA RASTOGI on 12/13/11.
// Copyright (c) 2011 Miso Media. All rights reserved.
//
#import "Cache.h"
@implementation Cache
+(void)setData:(NSString*)data forKey:(NSString*)key andExpiration:(NSDate*)expirationDate
{
NSMutableDictionary* cacheDict =[[NSMutableDictionary alloc] init];
// NSDate* currentDate = [NSDate date];
// NSDate* expirationDate = [currentDate dateByAddingTimeInterval:720];
//
[cacheDict setValue:expirationDate forKey:@"expiration"];
[cacheDict setValue:data forKey:@"data"];
[[NSUserDefaults standardUserDefaults] setObject:cacheDict forKey:key];
[cacheDict release];
}
+(NSString*)getData:(NSString*)key
{
NSDictionary* cacheDict = [[NSUserDefaults standardUserDefaults] objectForKey:key];
NSDate* expirationDate = [cacheDict valueForKey:@"expiration"];
NSTimeInterval timeDifference = [expirationDate timeIntervalSinceNow];
NSString* data;
if(timeDifference < 0)
{
data = nil;
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:key];
}
else
{
data = [cacheDict valueForKey:@"data"];
}
return data;
}
@end