Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOCacheManager Class Reference

#include <OOCacheManager.h>

+ Inheritance diagram for OOCacheManager:
+ Collaboration diagram for OOCacheManager:

Instance Methods

(id) - objectForKey:inCache:
 
(void) - setObject:forKey:inCache:
 
(void) - removeObjectForKey:inCache:
 
(void) - clearCache:
 
(void) - clearAllCaches
 
(void) - reloadAllCaches
 
(void) - setAllowCacheWrites:
 
(NSString *) - cacheDirectoryPathCreatingIfNecessary:
 
(void) - flush
 
(void) - finishOngoingFlush
 
(id) - init [implementation]
 
(void) - dealloc [implementation]
 
(NSString *) - description [implementation]
 
(NSString *) - cachePathCreatingIfNecessary: [implementation]
 
(void) - loadCache [implementation]
 
(void) - write [implementation]
 
(void) - clear [implementation]
 
(BOOL) - dirty [implementation]
 
(void) - markClean [implementation]
 
(NSDictionary *) - loadDict [implementation]
 
(BOOL) - writeDict: [implementation]
 
(void) - buildCachesFromDictionary: [implementation]
 
(NSDictionary *) - dictionaryOfCaches [implementation]
 
(BOOL) - directoryExists:create: [implementation]
 
(id) - copyWithZone: [implementation]
 
(id) - retain [implementation]
 
(NSUInteger) - retainCount [implementation]
 
(void) - release [implementation]
 
(id) - autorelease [implementation]
 

Class Methods

(OOCacheManager *) + sharedCache
 
(Octree *) + octreeForModel:
 
(void) + setOctree:forModel:
 
(static void) + VFRAddFace [implementation]
 
(static NSUInteger) + VFRGetCount [implementation]
 
(static NSUInteger) + VFRGetFaceAtIndex [implementation]
 
(NSDictionary *) + meshDataForName: [implementation]
 
(void) + setMeshData:forName: [implementation]
 
(id) + allocWithZone: [implementation]
 

Private Attributes

NSMutableDictionary * _caches
 
id _scheduledWrite
 
BOOL _permitWrites
 
BOOL _dirty
 

Detailed Description

Definition at line 35 of file OOCacheManager.h.

Method Documentation

◆ allocWithZone:

+ (id) allocWithZone: (NSZone *) inZone
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 114 of file OOCacheManager.m.

665{
666 if (sSingleton == nil)
667 {
668 sSingleton = [super allocWithZone:inZone];
669 return sSingleton;
670 }
671 return nil;
672}
673
static OODebugMonitor * sSingleton
return nil

◆ autorelease

- (id) autorelease
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 114 of file OOCacheManager.m.

698{
699 return self;
700}
701

◆ buildCachesFromDictionary:

- (void) buildCachesFromDictionary: (NSDictionary *) inDict
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

576{
577 NSEnumerator *keyEnum = nil;
578 id key = nil;
579 id value = nil;
580 NSMutableDictionary *cache = nil;
581
582 if (inDict == nil ) return;
583
584 [_caches release];
585 _caches = [[NSMutableDictionary alloc] initWithCapacity:[inDict count]];
586
587 for (keyEnum = [inDict keyEnumerator]; (key = [keyEnum nextObject]); )
588 {
589 value = [inDict oo_dictionaryForKey:key];
590 if (value != nil)
591 {
592 cache = [NSMutableDictionary dictionaryWithDictionary:value];
593 if (cache != nil)
594 {
595 [_caches setObject:cache forKey:key];
596 }
597 }
598 }
599}
600

◆ cacheDirectoryPathCreatingIfNecessary:

- (NSString *) cacheDirectoryPathCreatingIfNecessary: (BOOL) create

Definition at line 114 of file OOCacheManager.m.

302{
303 /* Construct the path to the directory for cache files, which is:
304 ~/Library/Caches/org.aegidian.oolite/
305 or
306 ~/GNUStep/Library/Caches/org.aegidian.oolite/
307 In addition to generally being the right place to put caches,
308 ~/Library/Caches has the particular advantage of not being indexed by
309 Spotlight or backed up by Time Machine.
310 */
311 NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
312 if (![self directoryExists:cachePath create:create]) return nil;
313
314#if !OOLITE_MAC_OS_X
315 // the old cache file on GNUstep was one level up, so remove it if it exists
316 [[NSFileManager defaultManager] removeFileAtPath:[cachePath stringByAppendingPathComponent:@"Oolite-cache.plist"] handler:nil];
317#endif
318
319 cachePath = [cachePath stringByAppendingPathComponent:@"org.aegidian.oolite"];
320 if (![self directoryExists:cachePath create:create]) return nil;
321 return cachePath;
322}
323

◆ cachePathCreatingIfNecessary:

- (NSString *) cachePathCreatingIfNecessary: (BOOL) inCreate
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

637{
638 NSString *cachePath = [self cacheDirectoryPathCreatingIfNecessary:create];
639 return [cachePath stringByAppendingPathComponent:@"Data Cache.plist"];
640}
641

◆ clear

- (void) clear
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

475{
476 [_caches release];
477 _caches = nil;
478}
479

◆ clearAllCaches

- (void) clearAllCaches

Definition at line 114 of file OOCacheManager.m.

263{
264 [self clear];
265 _caches = [[NSMutableDictionary alloc] init];
266 _dirty = YES;
267}
268
NSMutableDictionary * _caches

◆ clearCache:

- (void) clearCache: (NSString *) inCacheKey

Definition at line 114 of file OOCacheManager.m.

246{
247 NSParameterAssert(inCacheKey != nil);
248
249 if (nil != [_caches objectForKey:inCacheKey])
250 {
251 [_caches removeObjectForKey:inCacheKey];
252 _dirty = YES;
253 OODebugLog(kOOLogDataCacheClearSuccess, @"Cleared cache \"%@\".", inCacheKey);
254 }
255 else
256 {
257 OODebugLog(kOOLogDataCacheClearSuccess, @"No need to clear non-existent cache \"%@\".", inCacheKey);
258 }
259}
260
static NSString *const kOOLogDataCacheClearSuccess
#define OODebugLog(class, format,...)
Definition OOLogging.h:146

◆ copyWithZone:

- (id) copyWithZone: (NSZone *) inZone
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 114 of file OOCacheManager.m.

676{
677 return self;
678}
679

◆ dealloc

- (void) dealloc
implementation

Definition at line 114 of file OOCacheManager.m.

137{
138 [self clear];
139
140 [super dealloc];
141}
142

◆ description

- (NSString *) description
implementation

Definition at line 114 of file OOCacheManager.m.

145{
146 return [NSString stringWithFormat:@"<%@ %p>{dirty=%s}", [self class], self, [self dirty] ? "yes" : "no"];
147}
148

◆ dictionaryOfCaches

- (NSDictionary *) dictionaryOfCaches
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

603{
604 return [OODeepCopy(_caches) autorelease];
605}
606

◆ directoryExists:create:

- (BOOL) directoryExists: (NSString *) inPath
create: (BOOL) inCreate 
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

609{
610 BOOL exists, directory;
611 NSFileManager *fmgr = [NSFileManager defaultManager];
612
613 exists = [fmgr fileExistsAtPath:inPath isDirectory:&directory];
614
615 if (exists && !directory)
616 {
617 OOLog(kOOLogDataCacheBuildPathError, @"Expected %@ to be a folder, but it is a file.", inPath);
618 return NO;
619 }
620 if (!exists)
621 {
622 if (!inCreate) return NO;
623 if (![fmgr oo_createDirectoryAtPath:inPath attributes:nil])
624 {
625 OOLog(kOOLogDataCacheBuildPathError, @"Could not create folder %@.", inPath);
626 return NO;
627 }
628 }
629
630 return YES;
631}
632
static NSString *const kOOLogDataCacheBuildPathError
#define OOLog(class, format,...)
Definition OOLogging.h:88

◆ dirty

- (BOOL) dirty
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

482{
483 return _dirty;
484}
485

◆ finishOngoingFlush

- (void) finishOngoingFlush

Definition at line 114 of file OOCacheManager.m.

288{
289#if WRITE_ASYNC
291#endif
292}
293
void waitForTaskToComplete:(id< OOAsyncWorkTask > task)
OOAsyncWorkManager * sharedAsyncWorkManager()

◆ flush

- (void) flush

Definition at line 114 of file OOCacheManager.m.

278{
279 if (_permitWrites && [self dirty] && _scheduledWrite == nil)
280 {
281 [self write];
282 [self markClean];
283 }
284}
285

◆ init

- (id) init
implementation

Definition at line 114 of file OOCacheManager.m.

125{
126 self = [super init];
127 if (self != nil)
128 {
129 _permitWrites = YES;
130 [self loadCache];
131 }
132 return self;
133}
134

◆ loadCache

- (void) loadCache
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

330{
331 NSDictionary *cache = nil;
332 NSString *cacheVersion = nil;
333 NSString *ooliteVersion = nil;
334 NSData *endianTag = nil;
335 NSNumber *formatVersion = nil;
336 BOOL accept = YES;
337 uint64_t endianTagValue = 0;
338
339 ooliteVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
340
341 [self clear];
342
343 cache = [self loadDict];
344 if (cache != nil)
345 {
346 // We have a cache
347 OOLog(kOOLogDataCacheFound, @"%@", @"Found data cache.");
349
350 cacheVersion = [cache objectForKey:kCacheKeyVersion];
351 if (![cacheVersion isEqual:ooliteVersion])
352 {
353 OOLog(kOOLogDataCacheRebuild, @"Data cache version (%@) does not match Oolite version (%@), rebuilding cache.", cacheVersion, ooliteVersion);
354 accept = NO;
355 }
356
357 formatVersion = [cache objectForKey:kCacheKeyFormatVersion];
358 if (accept && [formatVersion unsignedIntValue] != kFormatVersionValue)
359 {
360 OOLog(kOOLogDataCacheRebuild, @"Data cache format (%@) is not supported format (%u), rebuilding cache.", formatVersion, kFormatVersionValue);
361 accept = NO;
362 }
363
364 if (accept)
365 {
366 endianTag = [cache objectForKey:kCacheKeyEndianTag];
367 if (![endianTag isKindOfClass:[NSData class]] || [endianTag length] != sizeof endianTagValue)
368 {
369 OOLog(kOOLogDataCacheRebuild, @"%@", @"Data cache endian tag is invalid, rebuilding cache.");
370 accept = NO;
371 }
372 else
373 {
374 endianTagValue = *(const uint64_t *)[endianTag bytes];
375 if (endianTagValue != kEndianTagValue)
376 {
377 OOLog(kOOLogDataCacheRebuild, @"%@", @"Data cache endianness is inappropriate for this system, rebuilding cache.");
378 accept = NO;
379 }
380 }
381 }
382
383 if (accept)
384 {
385 // We have a cache, and it's the right format.
386 [self buildCachesFromDictionary:[cache objectForKey:kCacheKeyCaches]];
387 }
388
390 }
391 else
392 {
393 // No cache
394 OOLog(kOOLogDataCacheNotFound, @"%@", @"No data cache found, starting from scratch.");
395 }
396
397 // If loading failed, or there was a version or endianness conflict
398 if (_caches == nil) _caches = [[NSMutableDictionary alloc] init];
399 [self markClean];
400}
401
@ kFormatVersionValue
@ kEndianTagValue
static NSString *const kOOLogDataCacheRebuild
static NSString *const kOOLogDataCacheNotFound
static NSString *const kOOLogDataCacheFound
#define OOLogOutdentIf(class)
Definition OOLogging.h:102
#define OOLogIndentIf(class)
Definition OOLogging.h:101

◆ loadDict

- (NSDictionary *) loadDict
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

494{
495 NSString *path = nil;
496 NSData *data = nil;
497 NSString *errorString = nil;
498 id contents = nil;
499
500 path = [self cachePathCreatingIfNecessary:NO];
501 if (path == nil) return nil;
502
503 @try
504 {
505 data = [NSData dataWithContentsOfFile:path];
506 if (data == nil) return nil;
507
508 contents = [NSPropertyListSerialization propertyListFromData:data
509 mutabilityOption:NSPropertyListImmutable
510 format:NULL
511 errorDescription:&errorString];
512 }
513 @catch (NSException *exception)
514 {
515 errorString = [exception reason];
516 contents = nil;
517 }
518
519 if (errorString != nil)
520 {
521 OOLog(@"dataCache.badData", @"Could not read data cache: %@", errorString);
522#if OOLITE_RELEASE_PLIST_ERROR_STRINGS
523 [errorString release];
524#endif
525 return nil;
526 }
527 if (![contents isKindOfClass:[NSDictionary class]]) return nil;
528
529 return contents;
530}
531

◆ markClean

- (void) markClean
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

488{
489 _dirty = NO;
490}
491

◆ meshDataForName:

+ (NSDictionary *) meshDataForName: (NSString *) inShipName
implementation

Provided by category OOCacheManager(OOMesh).

Definition at line 1792 of file OOMesh.m.

2218 :(NSString *)inShipName
2219{
2220 return [[self sharedCache] objectForKey:inShipName inCache:kOOCacheMeshes];
2221}

◆ objectForKey:inCache:

- (id) objectForKey: (NSString *) inKey
inCache: (NSString *) inCacheKey 

Definition at line 114 of file OOCacheManager.m.

163{
164 NSMutableDictionary *cache = nil;
165 id result = nil;
166
167 NSParameterAssert(inKey != nil && inCacheKey != nil);
168
169 cache = [_caches objectForKey:inCacheKey];
170 if (cache != nil)
171 {
172 result = [cache objectForKey:inKey];
173 if (result != nil)
174 {
175 OODebugLog(kOOLogDataCacheRetrieveSuccess, @"Retrieved \"%@\" cache object %@.", inCacheKey, inKey);
176 }
177 else
178 {
179 OODebugLog(kOOLogDataCacheRetrieveFailed, @"Failed to retrieve \"%@\" cache object %@ -- no such entry.", inCacheKey, inKey);
180 }
181 }
182 else
183 {
184 OODebugLog(kOOLogDataCacheRetrieveFailed, @"Failed to retrieve \"%@\" cache object %@ -- no such cache.", inCacheKey, inKey);
185 }
186
187 return result;
188}
189
static NSString *const kOOLogDataCacheRetrieveSuccess
static NSString *const kOOLogDataCacheRetrieveFailed

Referenced by LoadScriptWithName().

+ Here is the caller graph for this function:

◆ octreeForModel:

+ (Octree *) octreeForModel: (NSString *) inKey

Provided by category OOCacheManager(Octree).

Definition at line 1792 of file OOMesh.m.

2239 :(NSString *)inKey
2240{
2241 NSDictionary *dict = nil;
2242 Octree *result = nil;
2243
2244 if (inKey == nil) return nil;
2245
2246 dict = [[self sharedCache] objectForKey:inKey inCache:kOOCacheOctrees];
2247 if (dict != nil)
2248 {
2249 result = [[Octree alloc] initWithDictionary:dict];
2250 [result autorelease];
2251 }
2252
2253 return result;
2254}

◆ release

- (void) release
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 114 of file OOCacheManager.m.

694{}
695

◆ reloadAllCaches

- (void) reloadAllCaches

Definition at line 114 of file OOCacheManager.m.

271{
272 [self clear];
273 [self loadCache];
274}
275

◆ removeObjectForKey:inCache:

- (void) removeObjectForKey: (NSString *) inKey
inCache: (NSString *) inCacheKey 

Definition at line 114 of file OOCacheManager.m.

219{
220 NSMutableDictionary *cache = nil;
221
222 NSParameterAssert(inKey != nil && inCacheKey != nil);
223
224 cache = [_caches objectForKey:inCacheKey];
225 if (cache != nil)
226 {
227 if (nil != [cache objectForKey:inKey])
228 {
229 [cache removeObjectForKey:inKey];
230 _dirty = YES;
231 OODebugLog(kOOLogDataCacheRemoveSuccess, @"Removed entry keyed %@ from cache \"%@\".", inKey, inCacheKey);
232 }
233 else
234 {
235 OODebugLog(kOOLogDataCacheRemoveSuccess, @"No need to remove non-existent entry keyed %@ from cache \"%@\".", inKey, inCacheKey);
236 }
237 }
238 else
239 {
240 OODebugLog(kOOLogDataCacheRemoveSuccess, @"No need to remove entry keyed %@ from non-existent cache \"%@\".", inKey, inCacheKey);
241 }
242}
243
static NSString *const kOOLogDataCacheRemoveSuccess

◆ retain

- (id) retain
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 114 of file OOCacheManager.m.

682{
683 return self;
684}
685

◆ retainCount

- (NSUInteger) retainCount
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 114 of file OOCacheManager.m.

688{
689 return UINT_MAX;
690}
691

◆ setAllowCacheWrites:

- (void) setAllowCacheWrites: (BOOL) flag

Definition at line 114 of file OOCacheManager.m.

296{
297 _permitWrites = (flag != NO);
298}
299

◆ setMeshData:forName:

+ (void) setMeshData: (NSDictionary *) inData
forName: (NSString *) inShipName 
implementation

Provided by category OOCacheManager(OOMesh).

Definition at line 1792 of file OOMesh.m.

2224 :(NSDictionary *)inData forName:(NSString *)inShipName
2225{
2226 if (inData != nil && inShipName != nil)
2227 {
2228 [[self sharedCache] setObject:inData forKey:inShipName inCache:kOOCacheMeshes];
2229 }
2230}

◆ setObject:forKey:inCache:

- (void) setObject: (id) inElement
forKey: (NSString *) inKey
inCache: (NSString *) inCacheKey 

Definition at line 114 of file OOCacheManager.m.

193{
194 NSMutableDictionary *cache = nil;
195
196 NSParameterAssert(inObject != nil && inKey != nil && inCacheKey != nil);
197
198 if (EXPECT_NOT(_caches == nil)) return;
199
200 cache = [_caches objectForKey:inCacheKey];
201 if (cache == nil)
202 {
203 cache = [NSMutableDictionary dictionary];
204 if (cache == nil)
205 {
206 OODebugLog(kOOLogDataCacheSetFailed, @"Failed to create cache for key \"%@\".", inCacheKey);
207 return;
208 }
209 [_caches setObject:cache forKey:inCacheKey];
210 }
211
212 [cache setObject:inObject forKey:inKey];
213 _dirty = YES;
214 OODebugLog(kOOLogDataCacheSetSuccess, @"Updated entry %@ in cache \"%@\".", inKey, inCacheKey);
215}
216
static NSString *const kOOLogDataCacheSetFailed
static NSString *const kOOLogDataCacheSetSuccess
#define EXPECT_NOT(x)

Referenced by LoadScriptWithName().

+ Here is the caller graph for this function:

◆ setOctree:forModel:

+ (void) setOctree: (Octree *) inOctree
forModel: (NSString *) inKey 

Provided by category OOCacheManager(Octree).

Definition at line 1792 of file OOMesh.m.

2257 :(Octree *)inOctree forModel:(NSString *)inKey
2258{
2259 if (inOctree != nil && inKey != nil)
2260 {
2261 [[self sharedCache] setObject:[inOctree dictionaryRepresentation] forKey:inKey inCache:kOOCacheOctrees];
2262 }
2263}
NSDictionary * dictionaryRepresentation()
Definition Octree.m:667

◆ sharedCache

+ (OOCacheManager *) sharedCache

Definition at line 114 of file OOCacheManager.m.

151{
152 // NOTE: assumes single-threaded access.
153 if (sSingleton == nil)
154 {
155 sSingleton = [[self alloc] init];
156 }
157
158 return sSingleton;
159}
160

Referenced by LoadScriptWithName().

+ Here is the caller graph for this function:

◆ VFRAddFace

+ (static void) VFRAddFace (VertexFaceRef *) vfr
(NSUInteger) index 
implementation

Provided by category OOCacheManager(Octree).

Definition at line 2266 of file OOMesh.m.

2267{
2268 NSCParameterAssert(vfr != NULL);
2269
2270 if (index < UINT16_MAX && vfr->internCount < kVertexFaceDefInternalCount)
2271 {
2272 vfr->internFaces[vfr->internCount++] = index;
2273 }
2274 else
2275 {
2276 if (vfr->extra == nil) vfr->extra = [NSMutableArray array];
2277 [vfr->extra addObject:[NSNumber numberWithInteger:index]];
2278 }
2279}
@ kVertexFaceDefInternalCount
Definition OOMesh.m:113
uint16_t internFaces[kVertexFaceDefInternalCount]
Definition OOMesh.m:120
NSMutableArray * extra
Definition OOMesh.m:121

◆ VFRGetCount

+ (static NSUInteger) VFRGetCount (VertexFaceRef *) vfr
implementation

Provided by category OOCacheManager(Octree).

Definition at line 2282 of file OOMesh.m.

2283{
2284 NSCParameterAssert(vfr != NULL);
2285
2286 return vfr->internCount + [vfr->extra count];
2287}
unsigned count
uint16_t internCount
Definition OOMesh.m:119

◆ VFRGetFaceAtIndex

+ (static NSUInteger) VFRGetFaceAtIndex (VertexFaceRef *) vfr
(NSUInteger) index 
implementation

Provided by category OOCacheManager(Octree).

Definition at line 2290 of file OOMesh.m.

2291{
2292 NSCParameterAssert(vfr != NULL && index < VFRGetCount(vfr));
2293
2294 if (index < vfr->internCount) return vfr->internFaces[index];
2295 else return [vfr->extra oo_unsignedIntegerAtIndex:index - vfr->internCount];
2296}
static NSUInteger VFRGetCount(VertexFaceRef *vfr)
Definition OOMesh.m:2282

◆ write

- (void) write
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

404{
405 NSMutableDictionary *newCache = nil;
406 NSString *ooliteVersion = nil;
407 NSData *endianTag = nil;
408 NSNumber *formatVersion = nil;
409 NSDictionary *pListRep = nil;
410 uint64_t endianTagValue = kEndianTagValue;
411
412 if (_caches == nil) return;
413 if (_scheduledWrite != nil) return;
414
415#if PROFILE_WRITES
417#endif
418
419#if WRITE_ASYNC
420 OOLog(@"dataCache.willWrite", @"%@", @"Scheduling data cache write.");
421#else
422 OOLog(@"dataCache.willWrite", @"%@", @"About to write cache.");
423#endif
424
425 ooliteVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
426 endianTag = [NSData dataWithBytes:&endianTagValue length:sizeof endianTagValue];
427 formatVersion = [NSNumber numberWithUnsignedInt:kFormatVersionValue];
428
429 pListRep = [self dictionaryOfCaches];
430 if (ooliteVersion == nil || endianTag == nil || formatVersion == nil || pListRep == nil)
431 {
432 OOLog(@"dataCache.cantWrite", @"%@", @"Failed to write data cache -- prerequisites not fulfilled. This is an internal error, please report it.");
433 return;
434 }
435
436 newCache = [NSMutableDictionary dictionaryWithCapacity:4];
437 [newCache setObject:ooliteVersion forKey:kCacheKeyVersion];
438 [newCache setObject:formatVersion forKey:kCacheKeyFormatVersion];
439 [newCache setObject:endianTag forKey:kCacheKeyEndianTag];
440 [newCache setObject:pListRep forKey:kCacheKeyCaches];
441
442#if PROFILE_WRITES && !WRITE_ASYNC
443 OOTimeDelta prepareT = [stopwatch reset];
444#endif
445
446#if WRITE_ASYNC
447 NSDictionary *cacheData = newCache;
448 _scheduledWrite = [[OOAsyncCacheWriter alloc] initWithCacheContents:cacheData];
449
450#if PROFILE_WRITES
451 OOTimeDelta endT = [stopwatch reset];
452 OOLog(@"dataCache.profile", @"Time to prepare cache data: %g seconds.", endT);
453#endif
454
455 [[OOAsyncWorkManager sharedAsyncWorkManager] addTask:_scheduledWrite priority:kOOAsyncPriorityLow];
456#else
457#if PROFILE_WRITES
458 OOLog(@"dataCache.profile", @"Time to prepare cache data: %g seconds.", prepareT);
459#endif
460
461 if ([self writeDict:newCache])
462 {
463 [self markClean];
464 OOLog(kOOLogDataCacheWriteSuccess, @"%@", @"Wrote data cache.");
465 }
466 else
467 {
468 OOLog(kOOLogDataCacheWriteFailed, @"%@", @"Failed to write data cache.");
469 }
470#endif
471}
472
static NSString *const kOOLogDataCacheWriteSuccess
static NSString *const kOOLogDataCacheWriteFailed
double OOTimeDelta
Definition OOTypes.h:224
BOOL addTask:priority:(id< OOAsyncWorkTask > task,[priority] OOAsyncWorkPriority priority)

◆ writeDict:

- (BOOL) writeDict: (NSDictionary *) inDict
implementation

Provided by category OOCacheManager(Private).

Definition at line 114 of file OOCacheManager.m.

534{
535 NSString *path = nil;
536 NSData *plist = nil;
537 NSString *errorDesc = nil;
538
539 path = [self cachePathCreatingIfNecessary:YES];
540 if (path == nil) return NO;
541
542#if PROFILE_WRITES
544#endif
545
546 plist = [NSPropertyListSerialization dataFromPropertyList:inDict format:CACHE_PLIST_FORMAT errorDescription:&errorDesc];
547 if (plist == nil)
548 {
549#if OOLITE_RELEASE_PLIST_ERROR_STRINGS
550 [errorDesc autorelease];
551#endif
552 OOLog(kOOLogDataCacheSerializationError, @"Could not convert data cache to property list data: %@", errorDesc);
553 return NO;
554 }
555
556#if PROFILE_WRITES
557 OOTimeDelta serializeT = [stopwatch reset];
558#endif
559
560 BOOL result = [plist writeToFile:path atomically:NO];
561
562#if PROFILE_WRITES
563 OOTimeDelta writeT = [stopwatch reset];
564
565 OOLog(@"dataCache.profile", @"Time to serialize cache: %g seconds. Time to write data: %g seconds.", serializeT, writeT);
566#endif
567
568#if WRITE_ASYNC
569 DESTROY(_scheduledWrite);
570#endif
571 return result;
572}
573
static NSString *const kOOLogDataCacheSerializationError
#define DESTROY(x)
Definition OOCocoa.h:77

Member Data Documentation

◆ _caches

- (NSMutableDictionary*) _caches
private

Definition at line 38 of file OOCacheManager.h.

◆ _dirty

- (BOOL) _dirty
private

Definition at line 41 of file OOCacheManager.h.

◆ _permitWrites

- (BOOL) _permitWrites
private

Definition at line 40 of file OOCacheManager.h.

◆ _scheduledWrite

- (id) _scheduledWrite
private

Definition at line 39 of file OOCacheManager.h.


The documentation for this class was generated from the following files: