Skip to content
This repository
Browse code

Begone blasted tabs

  • Loading branch information...
commit 1af3cd81d6638a2547e952ae7988016b87321acc 1 parent 5ea39a8
authored November 26, 2009

Showing 1 changed file with 74 additions and 74 deletions. Show diff stats Hide diff stats

  1. 148  EGOCache.m
148  EGOCache.m
@@ -15,20 +15,20 @@
15 15
 static NSString* _EGOCacheDirectory;
16 16
 
17 17
 static inline NSString* EGOCacheDirectory() {
18  
-	if(!_EGOCacheDirectory) {
  18
+  if(!_EGOCacheDirectory) {
19 19
 #ifdef TARGET_OS_IPHONE
20  
-		_EGOCacheDirectory = [[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/EGOCache"] retain];
  20
+    _EGOCacheDirectory = [[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/EGOCache"] retain];
21 21
 #else
22  
-		NSString* appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0];
23  
-		_EGOCacheDirectory = [[[appSupportDir stringByAppendingPathComponent:[[NSProcessInfo processInfo] processName]] stringByAppendingPathComponent:@"EGOCache"] retain];
  22
+    NSString* appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  23
+    _EGOCacheDirectory = [[[appSupportDir stringByAppendingPathComponent:[[NSProcessInfo processInfo] processName]] stringByAppendingPathComponent:@"EGOCache"] retain];
24 24
 #endif
25  
-	}
26  
-	
27  
-	return _EGOCacheDirectory;
  25
+  }
  26
+  
  27
+  return _EGOCacheDirectory;
28 28
 }
29 29
 
30 30
 static inline NSString* cachePathForKey(NSString* key) {
31  
-	return [EGOCacheDirectory() stringByAppendingPathComponent:key];
  31
+  return [EGOCacheDirectory() stringByAppendingPathComponent:key];
32 32
 }
33 33
 
34 34
 static id __instance;
@@ -36,48 +36,48 @@
36 36
 @implementation EGOCache
37 37
 
38 38
 + (EGOCache*)currentCache {
39  
-	@synchronized(self) {
40  
-		if(!__instance) {
41  
-			__instance = [[EGOCache alloc] init];
42  
-		}
43  
-	}
44  
-	
45  
-	return __instance;
  39
+  @synchronized(self) {
  40
+    if(!__instance) {
  41
+      __instance = [[EGOCache alloc] init];
  42
+    }
  43
+  }
  44
+  
  45
+  return __instance;
46 46
 }
47 47
 
48 48
 - (id)init {
49  
-	if((self = [super init])) {
50  
-		NSDictionary* dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"EGOCache"];
51  
-		
52  
-		if([dict isKindOfClass:[NSDictionary class]]) {
53  
-			cacheDictionary = [dict mutableCopy];
54  
-		} else {
55  
-			cacheDictionary = [[NSMutableDictionary alloc] init];
56  
-		}
57  
-		
  49
+  if((self = [super init])) {
  50
+    NSDictionary* dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"EGOCache"];
  51
+    
  52
+    if([dict isKindOfClass:[NSDictionary class]]) {
  53
+      cacheDictionary = [dict mutableCopy];
  54
+    } else {
  55
+      cacheDictionary = [[NSMutableDictionary alloc] init];
  56
+    }
  57
+    
58 58
     diskOperationQueue = [[NSOperationQueue alloc] init];
59  
-		
60  
-		[[NSFileManager defaultManager] createDirectoryAtPath:EGOCacheDirectory() 
61  
-								  withIntermediateDirectories:YES 
62  
-												   attributes:nil 
63  
-														error:NULL];
64  
-		
65  
-		for(NSString* key in cacheDictionary) {
66  
-			NSDate* date = [cacheDictionary objectForKey:key];
67  
-			if([[[NSDate date] earlierDate:date] isEqualToDate:date]) {
68  
-				[[NSFileManager defaultManager] removeItemAtPath:cachePathForKey(key) error:NULL];
69  
-			}
70  
-		}
71  
-	}
72  
-	
73  
-	return self;
  59
+    
  60
+    [[NSFileManager defaultManager] createDirectoryAtPath:EGOCacheDirectory() 
  61
+                  withIntermediateDirectories:YES 
  62
+                           attributes:nil 
  63
+                            error:NULL];
  64
+    
  65
+    for(NSString* key in cacheDictionary) {
  66
+      NSDate* date = [cacheDictionary objectForKey:key];
  67
+      if([[[NSDate date] earlierDate:date] isEqualToDate:date]) {
  68
+        [[NSFileManager defaultManager] removeItemAtPath:cachePathForKey(key) error:NULL];
  69
+      }
  70
+    }
  71
+  }
  72
+  
  73
+  return self;
74 74
 }
75 75
 
76 76
 - (void)clearCache {
77  
-	for(NSString* key in cacheDictionary) {
  77
+  for(NSString* key in cacheDictionary) {
78 78
     [self removeItemFromCache:key];
79  
-	}
80  
-	[self saveCacheDictionary];
  79
+  }
  80
+  [self saveCacheDictionary];
81 81
 }
82 82
 
83 83
 - (void)clearCache:(NSString*)key {
@@ -91,21 +91,21 @@ - (void)removeItemFromCache:(NSString*)key {
91 91
 }
92 92
 
93 93
 - (BOOL)hasCacheForKey:(NSString*)key {
94  
-	NSDate* date = [cacheDictionary objectForKey:key];
95  
-	if(!date) return NO;
96  
-	if([[[NSDate date] earlierDate:date] isEqualToDate:date]) return NO;
97  
-	return [[NSFileManager defaultManager] fileExistsAtPath:cachePathForKey(key)];
  94
+  NSDate* date = [cacheDictionary objectForKey:key];
  95
+  if(!date) return NO;
  96
+  if([[[NSDate date] earlierDate:date] isEqualToDate:date]) return NO;
  97
+  return [[NSFileManager defaultManager] fileExistsAtPath:cachePathForKey(key)];
98 98
 }
99 99
 
100 100
 #pragma mark -
101 101
 #pragma mark Data methods
102 102
 
103 103
 - (void)setData:(NSData*)data forKey:(NSString*)key {
104  
-	[self setData:data forKey:key withTimeoutInterval:60 * 60 * 24];
  104
+  [self setData:data forKey:key withTimeoutInterval:60 * 60 * 24];
105 105
 }
106 106
 
107 107
 - (void)setData:(NSData*)data forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval {
108  
-	NSString *cachePath = cachePathForKey(key);
  108
+  NSString *cachePath = cachePathForKey(key);
109 109
   NSInvocation *diskWriteInvocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(writeData:toPath:)]];
110 110
   [diskWriteInvocation setTarget:self];
111 111
   [diskWriteInvocation setSelector:@selector(writeData:toPath:)];
@@ -116,22 +116,22 @@ - (void)setData:(NSData*)data forKey:(NSString*)key withTimeoutInterval:(NSTimeI
116 116
   [diskOperationQueue addOperation:diskWriteOperation];
117 117
   [diskWriteOperation release];
118 118
   
119  
-	[cacheDictionary setObject:[NSDate dateWithTimeIntervalSinceNow:timeoutInterval] forKey:key];
120  
-	
121  
-	[self performSelectorOnMainThread:@selector(saveAfterDelay) withObject:nil waitUntilDone:YES]; // Need to make sure the save delay get scheduled in the main runloop, not the current threads
  119
+  [cacheDictionary setObject:[NSDate dateWithTimeIntervalSinceNow:timeoutInterval] forKey:key];
  120
+  
  121
+  [self performSelectorOnMainThread:@selector(saveAfterDelay) withObject:nil waitUntilDone:YES]; // Need to make sure the save delay get scheduled in the main runloop, not the current threads
122 122
 }
123 123
 
124 124
 - (void)saveAfterDelay { // Prevents multiple-rapid user defaults saves from happening, which will slow down your app
125  
-	[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(saveCacheDictionary) object:nil];
126  
-	[self performSelector:@selector(saveCacheDictionary) withObject:nil afterDelay:0.3];
  125
+  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(saveCacheDictionary) object:nil];
  126
+  [self performSelector:@selector(saveCacheDictionary) withObject:nil afterDelay:0.3];
127 127
 }
128 128
 
129 129
 - (NSData*)dataForKey:(NSString*)key {
130  
-	if([self hasCacheForKey:key]) {
131  
-		return [NSData dataWithContentsOfFile:cachePathForKey(key) options:0 error:NULL];
132  
-	} else {
133  
-		return nil;
134  
-	}
  130
+  if([self hasCacheForKey:key]) {
  131
+    return [NSData dataWithContentsOfFile:cachePathForKey(key) options:0 error:NULL];
  132
+  } else {
  133
+    return nil;
  134
+  }
135 135
 }
136 136
 
137 137
 - (void)writeData:(NSData*)data toPath:(NSString *)path;
@@ -140,25 +140,25 @@ - (void)writeData:(NSData*)data toPath:(NSString *)path;
140 140
 } 
141 141
 
142 142
 - (void)saveCacheDictionary {
143  
-	@synchronized(self) {
144  
-		[[NSUserDefaults standardUserDefaults] setObject:cacheDictionary forKey:@"EGOCache"];
145  
-		[[NSUserDefaults standardUserDefaults] synchronize];
146  
-	}
  143
+  @synchronized(self) {
  144
+    [[NSUserDefaults standardUserDefaults] setObject:cacheDictionary forKey:@"EGOCache"];
  145
+    [[NSUserDefaults standardUserDefaults] synchronize];
  146
+  }
147 147
 }
148 148
 
149 149
 #pragma mark -
150 150
 #pragma mark String methods
151 151
 
152 152
 - (NSString*)stringForKey:(NSString*)key {
153  
-	return [[[NSString alloc] initWithData:[self dataForKey:key] encoding:NSUTF8StringEncoding] autorelease];
  153
+  return [[[NSString alloc] initWithData:[self dataForKey:key] encoding:NSUTF8StringEncoding] autorelease];
154 154
 }
155 155
 
156 156
 - (void)setString:(NSString*)aString forKey:(NSString*)key {
157  
-	[self setString:aString forKey:key withTimeoutInterval:60 * 60 * 24];
  157
+  [self setString:aString forKey:key withTimeoutInterval:60 * 60 * 24];
158 158
 }
159 159
 
160 160
 - (void)setString:(NSString*)aString forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval {
161  
-	[self setData:[aString dataUsingEncoding:NSUTF8StringEncoding] forKey:key withTimeoutInterval:timeoutInterval];
  161
+  [self setData:[aString dataUsingEncoding:NSUTF8StringEncoding] forKey:key withTimeoutInterval:timeoutInterval];
162 162
 }
163 163
 
164 164
 #pragma mark -
@@ -167,31 +167,31 @@ - (void)setString:(NSString*)aString forKey:(NSString*)key withTimeoutInterval:(
167 167
 #if TARGET_OS_IPHONE
168 168
 
169 169
 - (UIImage*)imageForKey:(NSString*)key {
170  
-	return [UIImage imageWithData:[self dataForKey:key]];
  170
+  return [UIImage imageWithData:[self dataForKey:key]];
171 171
 }
172 172
 
173 173
 - (void)setImage:(UIImage*)anImage forKey:(NSString*)key {
174  
-	[self setImage:anImage forKey:key withTimeoutInterval:60 * 60 * 24];
  174
+  [self setImage:anImage forKey:key withTimeoutInterval:60 * 60 * 24];
175 175
 }
176 176
 
177 177
 - (void)setImage:(UIImage*)anImage forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval {
178  
-	[self setData:UIImagePNGRepresentation(anImage) forKey:key withTimeoutInterval:timeoutInterval];
  178
+  [self setData:UIImagePNGRepresentation(anImage) forKey:key withTimeoutInterval:timeoutInterval];
179 179
 }
180 180
 
181 181
 
182 182
 #else
183 183
 
184 184
 - (NSImage*)imageForKey:(NSString*)key {
185  
-	return [[[NSImage alloc] initWithData:[self dataForKey:key]] autorelease];
  185
+  return [[[NSImage alloc] initWithData:[self dataForKey:key]] autorelease];
186 186
 }
187 187
 
188 188
 - (void)setImage:(NSImage*)anImage forKey:(NSString*)key {
189  
-	[self setImage:anImage forKey:key withTimeoutInterval:60 * 60 * 24];
  189
+  [self setImage:anImage forKey:key withTimeoutInterval:60 * 60 * 24];
190 190
 }
191 191
 
192 192
 - (void)setImage:(NSImage*)anImage forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval {
193  
-	[self setData:[[[anImage representations] objectAtIndex:0] representationUsingType:NSPNGFileType properties:nil]
194  
-		   forKey:key withTimeoutInterval:timeoutInterval];
  193
+  [self setData:[[[anImage representations] objectAtIndex:0] representationUsingType:NSPNGFileType properties:nil]
  194
+       forKey:key withTimeoutInterval:timeoutInterval];
195 195
 }
196 196
 
197 197
 #endif
@@ -200,8 +200,8 @@ - (void)setImage:(NSImage*)anImage forKey:(NSString*)key withTimeoutInterval:(NS
200 200
 
201 201
 - (void)dealloc {
202 202
   [diskOperationQueue release];
203  
-	[cacheDictionary release];
204  
-	[super dealloc];
  203
+  [cacheDictionary release];
  204
+  [super dealloc];
205 205
 }
206 206
 
207 207
 @end

0 notes on commit 1af3cd8

Please sign in to comment.
Something went wrong with that request. Please try again.