diff --git a/ChangeLog b/ChangeLog index a8973b897..3a5ea7823 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-11-16 Wolfgang Sourdeau + + * SoObjects/SOGo/SOGoCache.m: "cache", "users" and "localCache" + are now regular ivars. "sharedCache" is now located within the + "sharedCache" constructor. "killCache" is now an instance method. + 2009-11-10 Francis Lachapelle * UI/Scheduler/UIxComponentEditor.m (-_handleAttendeesEdition): diff --git a/Main/SOGo.m b/Main/SOGo.m index 1d56d3f30..fab8497c0 100644 --- a/Main/SOGo.m +++ b/Main/SOGo.m @@ -424,9 +424,7 @@ static BOOL debugObjectAllocation = NO; if (debugLeaks) { if (debugOn) - { - NSLog (@"allocated classes:\n%s", GSDebugAllocationList (YES)); - } + NSLog (@"allocated classes:\n%s", GSDebugAllocationList (YES)); else { debugOn = YES; @@ -435,7 +433,7 @@ static BOOL debugObjectAllocation = NO; } resp = [super dispatchRequest: _request]; - [SOGoCache killCache]; + [cache killCache]; if (debugRequests) { diff --git a/SoObjects/SOGo/SOGoCache.h b/SoObjects/SOGo/SOGoCache.h index 8b26b2a15..84cb876fb 100644 --- a/SoObjects/SOGo/SOGoCache.h +++ b/SoObjects/SOGo/SOGoCache.h @@ -38,6 +38,9 @@ @interface SOGoCache : NSObject { + NSMutableDictionary *localCache; + NSMutableDictionary *cache; + NSMutableDictionary *users; @private memcached_server_st *servers; memcached_st *handle; @@ -45,7 +48,8 @@ + (NSTimeInterval) cleanupInterval; + (SOGoCache *) sharedCache; -+ (void) killCache; + +- (void) killCache; - (void) registerObject: (id) object withName: (NSString *) name diff --git a/SoObjects/SOGo/SOGoCache.m b/SoObjects/SOGo/SOGoCache.m index 636c5f71d..2bcd699ff 100644 --- a/SoObjects/SOGo/SOGoCache.m +++ b/SoObjects/SOGo/SOGoCache.m @@ -54,32 +54,20 @@ // high to avoid useless database calls. static NSTimeInterval cleanupInterval = 300; -static NSMutableDictionary *cache = nil; -static NSMutableDictionary *users = nil; - -// localCache is used to avoid going all the time to the memcached server during -// each request. We'll cache the value we got from memcached for the duration -// of the current request - which is good enough for pretty much all caces. We -// surely don't want to get new defaults/settings during the _same_ requests, it -// could produce relatively strange behaviors -static NSMutableDictionary *localCache = nil; - static NSString *memcachedServerName = @"localhost"; -static SOGoCache *sharedCache = nil; - #if defined(THREADSAFE) static NSLock *lock; #endif @implementation SOGoCache +#if defined(THREADSAFE) + (void) initialize { -#if defined(THREADSAFE) lock = [NSLock new]; -#endif } +#endif + (NSTimeInterval) cleanupInterval { @@ -88,6 +76,8 @@ static NSLock *lock; + (SOGoCache *) sharedCache { + static SOGoCache *sharedCache = nil; + #if defined(THREADSAFE) [lock lock]; #endif @@ -100,7 +90,7 @@ static NSLock *lock; return sharedCache; } -+ (void) killCache +- (void) killCache { #if defined(THREADSAFE) [lock lock]; @@ -125,6 +115,12 @@ static NSLock *lock; cache = [[NSMutableDictionary alloc] init]; users = [[NSMutableDictionary alloc] init]; + + // localCache is used to avoid going all the time to the memcached server during + // each request. We'll cache the value we got from memcached for the duration + // of the current request - which is good enough for pretty much all caces. We + // surely don't want to get new defaults/settings during the _same_ requests, it + // could produce relatively strange behaviors localCache = [[NSMutableDictionary alloc] init]; // We fire our timer that will cleanup cache entries