Oolite 1.91.0.7745-260117-205bce7
Loading...
Searching...
No Matches
OOCache Class Reference

#include <OOCache.h>

Inheritance diagram for OOCache:
Collaboration diagram for OOCache:

Instance Methods

(id) - init
(id) - initWithPList:
(id) - pListRepresentation
(id) - objectForKey:
(void) - setObject:forKey:
(void) - removeObjectForKey:
(void) - setPruneThreshold:
(unsigned) - pruneThreshold
(void) - setAutoPrune:
(BOOL) - autoPrune
(void) - prune
(BOOL) - dirty
(void) - markClean
(NSString *) - name
(void) - setName:
(NSArray *) - objectsByAge
(void) - dealloc [implementation]
(NSString *) - description [implementation]
(void) - loadFromArray: [implementation]

Private Attributes

struct OOCacheImplcache
unsigned pruneThreshold
BOOL autoPrune
BOOL dirty

Detailed Description

Definition at line 57 of file OOCache.h.

Method Documentation

◆ autoPrune

- (BOOL) autoPrune

References autoPrune, and prune.

Here is the call graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 197 of file OOCache.m.

198{
199 CHECK_INTEGRITY(@"dealloc");
201
202 [super dealloc];
203}
static void CacheFree(OOCacheImpl *cache)
Definition OOCache.m:452
#define CHECK_INTEGRITY(context)
Definition OOCache.m:183
struct OOCacheImpl * cache
Definition OOCache.h:60

References cache, CacheFree(), CHECK_INTEGRITY, and dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ description

- (NSString *) description
implementation

Definition at line 206 of file OOCache.m.

207{
208 return [NSString stringWithFormat:@"<%@ %p>{\"%@\", %u elements, prune threshold=%u, auto-prune=%s dirty=%s}", [self class], self, [self name], CacheGetCount(cache), pruneThreshold, autoPrune ? "yes" : "no", dirty ? "yes" : "no"];
209}

References description, and name.

Referenced by description.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dirty

- (BOOL) dirty

References dirty, markClean, name, and objectsByAge.

Here is the call graph for this function:

◆ init

- (id) init

Definition at line 212 of file OOCache.m.

213{
214 return [self initWithPList:nil];
215}

References init, and initWithPList:.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithPList:

- (id) initWithPList: (id) pList

Definition at line 218 of file OOCache.m.

218 :(id)pList
219{
220 BOOL OK = YES;
221
222 self = [super init];
223 OK = self != nil;
224
225 if (OK)
226 {
228 if (cache == NULL) OK = NO;
229 }
230
231 if (pList != nil)
232 {
233 if (OK) OK = [pList isKindOfClass:[NSArray class]];
234 if (OK) [self loadFromArray:pList];
235 }
236 if (OK)
237 {
239 autoPrune = YES;
240 }
241
242 if (!OK)
243 {
244 [self release];
245 self = nil;
246 }
247
248 return self;
249}
@ kOOCacheDefaultPruneThreshold
Definition OOCache.h:52
static OOCacheImpl * CacheAllocate(void)
Definition OOCache.m:446
return nil
BOOL autoPrune
Definition OOCache.m:327
unsigned pruneThreshold
Definition OOCache.m:310

References autoPrune, cache, CacheAllocate(), kOOCacheDefaultPruneThreshold, loadFromArray:, nil, and pruneThreshold.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromArray:

- (void) loadFromArray: (NSArray *) inArray
implementation

Provided by category OOCache(Private).

Definition at line 391 of file OOCache.m.

391 :(NSArray *)array
392{
393 NSEnumerator *entryEnum = nil;
394 NSDictionary *entry = nil;
395 NSString *key = nil;
396 id value = nil;
397
398 if (array == nil) return;
399
400 for (entryEnum = [array objectEnumerator]; (entry = [entryEnum nextObject]); )
401 {
402 if ([entry isKindOfClass:[NSDictionary class]])
403 {
404 key = [entry objectForKey:kSerializedEntryKeyKey];
405 value = [entry objectForKey:kSerializedEntryKeyValue];
406 if ([key isKindOfClass:[NSString class]] && value != nil)
407 {
408 [self setObject:value forKey:key];
409 }
410 }
411 }
412}

Referenced by initWithPList:.

Here is the caller graph for this function:

◆ markClean

- (void) markClean

Definition at line 363 of file OOCache.m.

364{
365 dirty = NO;
366}
BOOL dirty
Definition OOCache.m:357

References dirty, and markClean.

Referenced by dirty, and markClean.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name

- (NSString *) name

Definition at line 369 of file OOCache.m.

370{
371 return CacheGetName(cache);
372}
static NSString * CacheGetName(OOCacheImpl *cache)
Definition OOCache.m:568

References cache, CacheGetName(), and name.

Referenced by description, dirty, name, and setName:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ objectForKey:

- (id) objectForKey: (id) key

Definition at line 260 of file OOCache.m.

260 :(id)key
261{
262 id result = nil;
263
264 CHECK_INTEGRITY(@"objectForKey: before");
265
266 result = CacheRetrieve(cache, key);
267 // Note: while reordering the age list technically makes the cache dirty, it's not worth rewriting it just for that, so we don't flag it.
268
269 CHECK_INTEGRITY(@"objectForKey: after");
270
271 return [[result retain] autorelease];
272}
static id CacheRetrieve(OOCacheImpl *cache, id key)
Definition OOCache.m:517

References cache, CacheRetrieve(), CHECK_INTEGRITY, and nil.

Referenced by OOEncodingConverter::convertString:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ objectsByAge

- (NSArray *) objectsByAge

Definition at line 381 of file OOCache.m.

382{
384}
static NSArray * CacheArrayOfContentsByAge(OOCacheImpl *cache)
Definition OOCache.m:534

References cache, CacheArrayOfContentsByAge(), and objectsByAge.

Referenced by OOTexture::cachedTexturesByAge, dirty, and objectsByAge.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pListRepresentation

- (id) pListRepresentation

Definition at line 252 of file OOCache.m.

253{
255
256 return nil;
257}
static NSArray * CacheArrayOfNodesByAge(OOCacheImpl *cache)
Definition OOCache.m:551

References cache, CacheArrayOfNodesByAge(), nil, and pListRepresentation.

Referenced by pListRepresentation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prune

- (void) prune

Definition at line 333 of file OOCache.m.

334{
335 unsigned pruneCount;
336 unsigned desiredCount;
337 unsigned count;
338
339 // Order of operations is to ensure rounding down.
340 if (autoPrune) desiredCount = (pruneThreshold * 4) / 5;
341 else desiredCount = pruneThreshold;
342
344
345 pruneCount = count - desiredCount;
346
347 NSString *logKey = [NSString stringWithFormat:@"dataCache.prune.%@", CacheGetName(cache)];
348 OOLog(logKey, @"Pruning cache \"%@\" - removing %u entries", CacheGetName(cache), pruneCount);
349 OOLogIndentIf(logKey);
350
351 while (pruneCount--) CacheRemoveOldest(cache, logKey);
352
353 OOLogOutdentIf(logKey);
354}
@ kOOCacheNoPrune
Definition OOCache.h:53
static unsigned CacheGetCount(OOCacheImpl *cache)
Definition OOCache.m:581
static BOOL CacheRemoveOldest(OOCacheImpl *cache, NSString *logKey)
Definition OOCache.m:507
#define OOLogOutdentIf(class)
Definition OOLogging.h:102
#define OOLog(class, format,...)
Definition OOLogging.h:88
#define OOLogIndentIf(class)
Definition OOLogging.h:101
unsigned count

References autoPrune, cache, CacheGetCount(), CacheGetName(), CacheRemoveOldest(), count, kOOCacheNoPrune, OOLog, OOLogIndentIf, OOLogOutdentIf, prune, and pruneThreshold.

Referenced by autoPrune, prune, setAutoPrune:, setObject:forKey:, and setPruneThreshold:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pruneThreshold

- (unsigned) pruneThreshold

References pruneThreshold.

◆ removeObjectForKey:

- (void) removeObjectForKey: (id) key

Definition at line 289 of file OOCache.m.

289 :(id)key
290{
291 CHECK_INTEGRITY(@"removeObjectForKey: before");
292
293 if (CacheRemove(cache, key)) dirty = YES;
294
295 CHECK_INTEGRITY(@"removeObjectForKey: after");
296}
static BOOL CacheRemove(OOCacheImpl *cache, id key)
Definition OOCache.m:478

References cache, CacheRemove(), CHECK_INTEGRITY, and dirty.

Referenced by OOTexture(SubclassInterface)::removeFromCaches.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAutoPrune:

- (void) setAutoPrune: (BOOL) flag

Definition at line 316 of file OOCache.m.

316 :(BOOL)flag
317{
318 BOOL prune = (flag != NO);
319 if (prune != autoPrune)
320 {
322 [self prune];
323 }
324}
void prune()
Definition OOCache.m:333

References autoPrune, and prune.

Referenced by OOTexture(OOPrivate)::addToCaches.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setName:

- (void) setName: (NSString *) name

Definition at line 375 of file OOCache.m.

375 :(NSString *)name
376{
378}
static void CacheSetName(OOCacheImpl *cache, NSString *name)
Definition OOCache.m:574
NSString * name()
Definition OOCache.m:369

References cache, CacheSetName(), and name.

Referenced by OOTexture(OOPrivate)::addToCaches, and OOEncodingConverter::initWithEncoding:substitutions:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setObject:forKey:

- (void) setObject: (id) value
forKey: (id) key 

Definition at line 275 of file OOCache.m.

275 :inObject forKey:(id)key
276{
277 CHECK_INTEGRITY(@"setObject:forKey: before");
278
279 if (CacheInsert(cache, key, inObject))
280 {
281 dirty = YES;
282 if (autoPrune) [self prune];
283 }
284
285 CHECK_INTEGRITY(@"setObject:forKey: after");
286}
static BOOL CacheInsert(OOCacheImpl *cache, id key, id value)
Definition OOCache.m:462

References autoPrune, cache, CacheInsert(), CHECK_INTEGRITY, dirty, and prune.

Referenced by OOTexture(OOPrivate)::addToCaches, PlayerEntity::commanderDataDictionary, OOEncodingConverter::convertString:, OOShipRegistry(OODataLoader)::loadCachedRoleProbabilitySets, and OOCache(Private)::loadFromArray:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPruneThreshold:

- (void) setPruneThreshold: (unsigned) threshold

Definition at line 299 of file OOCache.m.

299 :(unsigned)threshold
300{
301 threshold = MAX(threshold, (unsigned)kOOCacheMinimumPruneThreshold);
302 if (threshold != pruneThreshold)
303 {
304 pruneThreshold = threshold;
305 if (autoPrune) [self prune];
306 }
307}
@ kOOCacheMinimumPruneThreshold
Definition OOCache.h:51
#define MAX(A, B)
Definition OOMaths.h:114

References autoPrune, kOOCacheMinimumPruneThreshold, MAX, prune, and pruneThreshold.

Referenced by OOTexture(OOPrivate)::addToCaches, and OOEncodingConverter::initWithEncoding:substitutions:.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ autoPrune

- (BOOL) autoPrune
private

Definition at line 327 of file OOCache.m.

328{
329 return autoPrune;
330}

Referenced by autoPrune, initWithPList:, prune, setAutoPrune:, setObject:forKey:, and setPruneThreshold:.

◆ cache

- (struct OOCacheImpl*) cache
private

◆ dirty

- (BOOL) dirty
private

Definition at line 357 of file OOCache.m.

358{
359 return dirty;
360}

Referenced by dirty, markClean, removeObjectForKey:, and setObject:forKey:.

◆ pruneThreshold

- (unsigned) pruneThreshold
private

Definition at line 310 of file OOCache.m.

311{
312 return pruneThreshold;
313}

Referenced by initWithPList:, prune, pruneThreshold, and setPruneThreshold:.


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