Oolite 1.91.0.7665-250419-c535bfe
All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 170 of file OOCache.m.

171{
172 CHECK_INTEGRITY(@"dealloc");
174
175 [super dealloc];
176}
static void CacheFree(OOCacheImpl *cache)
Definition OOCache.m:451
#define CHECK_INTEGRITY(context)
Definition OOCache.m:156
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 179 of file OOCache.m.

180{
181 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"];
182}

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 185 of file OOCache.m.

186{
187 return [self initWithPList:nil];
188}

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 191 of file OOCache.m.

191 :(id)pList
192{
193 BOOL OK = YES;
194
195 self = [super init];
196 OK = self != nil;
197
198 if (OK)
199 {
201 if (cache == NULL) OK = NO;
202 }
203
204 if (pList != nil)
205 {
206 if (OK) OK = [pList isKindOfClass:[NSArray class]];
207 if (OK) [self loadFromArray:pList];
208 }
209 if (OK)
210 {
212 autoPrune = YES;
213 }
214
215 if (!OK)
216 {
217 [self release];
218 self = nil;
219 }
220
221 return self;
222}
@ kOOCacheDefaultPruneThreshold
Definition OOCache.h:52
static OOCacheImpl * CacheAllocate(void)
Definition OOCache.m:445
return nil
BOOL autoPrune
Definition OOCache.m:300
unsigned pruneThreshold
Definition OOCache.m:283

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 364 of file OOCache.m.

364 :(NSArray *)array
365{
366 NSEnumerator *entryEnum = nil;
367 NSDictionary *entry = nil;
368 NSString *key = nil;
369 id value = nil;
370
371 if (array == nil) return;
372
373 for (entryEnum = [array objectEnumerator]; (entry = [entryEnum nextObject]); )
374 {
375 if ([entry isKindOfClass:[NSDictionary class]])
376 {
377 key = [entry objectForKey:kSerializedEntryKeyKey];
378 value = [entry objectForKey:kSerializedEntryKeyValue];
379 if ([key isKindOfClass:[NSString class]] && value != nil)
380 {
381 [self setObject:value forKey:key];
382 }
383 }
384 }
385}

Referenced by initWithPList:.

+ Here is the caller graph for this function:

◆ markClean

- (void) markClean

Definition at line 336 of file OOCache.m.

337{
338 dirty = NO;
339}
BOOL dirty
Definition OOCache.m:330

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 342 of file OOCache.m.

343{
344 return CacheGetName(cache);
345}
static NSString * CacheGetName(OOCacheImpl *cache)
Definition OOCache.m:567

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 233 of file OOCache.m.

233 :(id)key
234{
235 id result = nil;
236
237 CHECK_INTEGRITY(@"objectForKey: before");
238
239 result = CacheRetrieve(cache, key);
240 // 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.
241
242 CHECK_INTEGRITY(@"objectForKey: after");
243
244 return [[result retain] autorelease];
245}
static id CacheRetrieve(OOCacheImpl *cache, id key)
Definition OOCache.m:516

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 354 of file OOCache.m.

355{
357}
static NSArray * CacheArrayOfContentsByAge(OOCacheImpl *cache)
Definition OOCache.m:533

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 225 of file OOCache.m.

226{
228
229 return nil;
230}
static NSArray * CacheArrayOfNodesByAge(OOCacheImpl *cache)
Definition OOCache.m:550

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 306 of file OOCache.m.

307{
308 unsigned pruneCount;
309 unsigned desiredCount;
310 unsigned count;
311
312 // Order of operations is to ensure rounding down.
313 if (autoPrune) desiredCount = (pruneThreshold * 4) / 5;
314 else desiredCount = pruneThreshold;
315
317
318 pruneCount = count - desiredCount;
319
320 NSString *logKey = [NSString stringWithFormat:@"dataCache.prune.%@", CacheGetName(cache)];
321 OOLog(logKey, @"Pruning cache \"%@\" - removing %u entries", CacheGetName(cache), pruneCount);
322 OOLogIndentIf(logKey);
323
324 while (pruneCount--) CacheRemoveOldest(cache, logKey);
325
326 OOLogOutdentIf(logKey);
327}
@ kOOCacheNoPrune
Definition OOCache.h:53
static unsigned CacheGetCount(OOCacheImpl *cache)
Definition OOCache.m:580
static BOOL CacheRemoveOldest(OOCacheImpl *cache, NSString *logKey)
Definition OOCache.m:506
#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 262 of file OOCache.m.

262 :(id)key
263{
264 CHECK_INTEGRITY(@"removeObjectForKey: before");
265
266 if (CacheRemove(cache, key)) dirty = YES;
267
268 CHECK_INTEGRITY(@"removeObjectForKey: after");
269}
static BOOL CacheRemove(OOCacheImpl *cache, id key)
Definition OOCache.m:477

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 289 of file OOCache.m.

289 :(BOOL)flag
290{
291 BOOL prune = (flag != NO);
292 if (prune != autoPrune)
293 {
295 [self prune];
296 }
297}
void prune()
Definition OOCache.m:306

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 348 of file OOCache.m.

348 :(NSString *)name
349{
351}
static void CacheSetName(OOCacheImpl *cache, NSString *name)
Definition OOCache.m:573
NSString * name()
Definition OOCache.m:342

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 248 of file OOCache.m.

248 :inObject forKey:(id)key
249{
250 CHECK_INTEGRITY(@"setObject:forKey: before");
251
252 if (CacheInsert(cache, key, inObject))
253 {
254 dirty = YES;
255 if (autoPrune) [self prune];
256 }
257
258 CHECK_INTEGRITY(@"setObject:forKey: after");
259}
static BOOL CacheInsert(OOCacheImpl *cache, id key, id value)
Definition OOCache.m:461

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 272 of file OOCache.m.

272 :(unsigned)threshold
273{
274 threshold = MAX(threshold, (unsigned)kOOCacheMinimumPruneThreshold);
275 if (threshold != pruneThreshold)
276 {
277 pruneThreshold = threshold;
278 if (autoPrune) [self prune];
279 }
280}
@ 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 300 of file OOCache.m.

301{
302 return autoPrune;
303}

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

◆ cache

- (struct OOCacheImpl*) cache
private

◆ dirty

- (BOOL) dirty
private

Definition at line 330 of file OOCache.m.

331{
332 return dirty;
333}

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

◆ pruneThreshold

- (unsigned) pruneThreshold
private

Definition at line 283 of file OOCache.m.

284{
285 return pruneThreshold;
286}

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


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