Oolite
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 OOCacheImpl * cache
unsigned pruneThreshold
BOOL autoPrune
BOOL dirty

Detailed Description

Definition at line 54 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 185 of file OOCache.m.

186{
187 CHECK_INTEGRITY(@"dealloc");
189
190 [super dealloc];
191}
static void CacheFree(OOCacheImpl *cache)
Definition OOCache.m:419
#define CHECK_INTEGRITY(context)
Definition OOCache.m:172
struct OOCacheImpl * cache
Definition OOCache.h:56

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

194{
195 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"];
196}

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

199{
200 return [self initWithPList:nil];
201}

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

203 :(id)pList
204{
205 BOOL OK = YES;
206
207 self = [super init];
208 OK = self != nil;
209
210 if (OK) {
212 if (cache == NULL)
213 OK = NO;
214 }
215
216 if (pList != nil) {
217 if (OK)
218 OK = [pList isKindOfClass:[NSArray class]];
219 if (OK)
220 [self loadFromArray:pList];
221 }
222 if (OK) {
224 autoPrune = YES;
225 }
226
227 if (!OK) {
228 [self release];
229 self = nil;
230 }
231
232 return self;
233}
@ kOOCacheDefaultPruneThreshold
Definition OOCache.h:50
static OOCacheImpl * CacheAllocate(void)
Definition OOCache.m:414
return nil
BOOL autoPrune
Definition OOCache.m:303
unsigned pruneThreshold
Definition OOCache.m:289

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 NSDictionary* entry = nil;
367 NSString* key = nil;
368 id value = nil;
369
370 if (array == nil)
371 return;
372
373 foreach (entry, array) {
374 if ([entry isKindOfClass:[NSDictionary class]]) {
375 key = [entry objectForKey:kSerializedEntryKeyKey];
376 value = [entry objectForKey:kSerializedEntryKeyValue];
377 if ([key isKindOfClass:[NSString class]] && value != nil) {
378 [self setObject:value forKey:key];
379 }
380 }
381 }
382}

Referenced by initWithPList:.

Here is the caller graph for this function:

◆ markClean

- (void) markClean

Definition at line 340 of file OOCache.m.

341{
342 dirty = NO;
343}
BOOL dirty
Definition OOCache.m:335

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

346{
347 return CacheGetName(cache);
348}
static NSString * CacheGetName(OOCacheImpl *cache)
Definition OOCache.m:529

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

242 :(id)key
243{
244 id result = nil;
245
246 CHECK_INTEGRITY(@"objectForKey: before");
247
248 result = CacheRetrieve(cache, key);
249 // 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.
250
251 CHECK_INTEGRITY(@"objectForKey: after");
252
253 return [[result retain] autorelease];
254}
static id CacheRetrieve(OOCacheImpl *cache, id key)
Definition OOCache.m:481

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

356{
358}
static NSArray * CacheArrayOfContentsByAge(OOCacheImpl *cache)
Definition OOCache.m:497

References cache, CacheArrayOfContentsByAge(), and objectsByAge.

Referenced by 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 235 of file OOCache.m.

236{
238
239 return nil;
240}
static NSArray * CacheArrayOfNodesByAge(OOCacheImpl *cache)
Definition OOCache.m:513

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

309{
310 unsigned pruneCount;
311 unsigned desiredCount;
312 unsigned count;
313
314 // Order of operations is to ensure rounding down.
315 if (autoPrune)
316 desiredCount = (pruneThreshold * 4) / 5;
317 else
318 desiredCount = pruneThreshold;
319
321 return;
322
323 pruneCount = count - desiredCount;
324
325 NSString* logKey = [NSString stringWithFormat:@"dataCache.prune.%@", CacheGetName(cache)];
326 OOLog(logKey, @"Pruning cache \"%@\" - removing %u entries", CacheGetName(cache), pruneCount);
327 OOLogIndentIf(logKey);
328
329 while (pruneCount--)
330 CacheRemoveOldest(cache, logKey);
331
332 OOLogOutdentIf(logKey);
333}
@ kOOCacheNoPrune
Definition OOCache.h:51
static unsigned CacheGetCount(OOCacheImpl *cache)
Definition OOCache.m:540
static BOOL CacheRemoveOldest(OOCacheImpl *cache, NSString *logKey)
Definition OOCache.m:471
#define OOLogOutdentIf(class)
Definition OOLogging.h:112
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define OOLogIndentIf(class)
Definition OOLogging.h:107
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 269 of file OOCache.m.

269 :(id)key
270{
271 CHECK_INTEGRITY(@"removeObjectForKey: before");
272
273 if (CacheRemove(cache, key))
274 dirty = YES;
275
276 CHECK_INTEGRITY(@"removeObjectForKey: after");
277}
static BOOL CacheRemove(OOCacheImpl *cache, id key)
Definition OOCache.m:444

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

294 :(BOOL)flag
295{
296 BOOL prune = (flag != NO);
297 if (prune != autoPrune) {
299 [self prune];
300 }
301}
void prune()
Definition OOCache.m:308

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

350 :(NSString*)name
351{
353}
static void CacheSetName(OOCacheImpl *cache, NSString *name)
Definition OOCache.m:534
NSString * name()
Definition OOCache.m:345

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

256 :(id)value forKey:(id)key
257{
258 CHECK_INTEGRITY(@"setObject:forKey: before");
259
260 if (CacheInsert(cache, key, value)) {
261 dirty = YES;
262 if (autoPrune)
263 [self prune];
264 }
265
266 CHECK_INTEGRITY(@"setObject:forKey: after");
267}
static BOOL CacheInsert(OOCacheImpl *cache, id key, id value)
Definition OOCache.m:429

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

279 :(unsigned)threshold
280{
281 threshold = MAX(threshold, (unsigned)kOOCacheMinimumPruneThreshold);
282 if (threshold != pruneThreshold) {
283 pruneThreshold = threshold;
284 if (autoPrune)
285 [self prune];
286 }
287}
@ kOOCacheMinimumPruneThreshold
Definition OOCache.h:49
#define MAX(A, B)
Definition OOMaths.h:94

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

304{
305 return autoPrune;
306}

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

◆ cache

- (struct OOCacheImpl*) cache
private

◆ dirty

- (BOOL) dirty
private

Definition at line 335 of file OOCache.m.

336{
337 return dirty;
338}

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

◆ pruneThreshold

- (unsigned) pruneThreshold
private

Definition at line 289 of file OOCache.m.

290{
291 return pruneThreshold;
292}

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


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