]> err.no Git - scalable-opengroupware.org/commitdiff
added SOGoLRUCache and made AgenorUserManager use it
authorznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Mon, 1 Nov 2004 00:53:29 +0000 (00:53 +0000)
committerznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Mon, 1 Nov 2004 00:53:29 +0000 (00:53 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@445 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGo/SOGo.xcode/project.pbxproj
SOGoLogic/AgenorUserManager.h
SOGoLogic/AgenorUserManager.m
SOGoLogic/ChangeLog
SOGoLogic/GNUmakefile
SOGoLogic/SOGoLRUCache.h [new file with mode: 0644]
SOGoLogic/SOGoLRUCache.m [new file with mode: 0644]
SOGoLogic/Version

index e42edc91c215f9430b5d54ad388bfba84aec4d94..48e0ed94bb1feff03b814709c2b8931c7baed1f0 100644 (file)
                                AD73BE4B06CF88BF00226A2D,
                                AD071D1206CD2BCB00A9EEF4,
                                AD071D1306CD2BCB00A9EEF4,
+                               AD255F390735B15E00D424E6,
+                               AD255F3A0735B15E00D424E6,
                                ADA6333607140E0D0058C21C,
                        );
                        isa = PBXGroup;
                        tabWidth = 8;
                        usesTabs = 1;
                };
+               AD255F390735B15E00D424E6 = {
+                       fileEncoding = 5;
+                       indentWidth = 2;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = SOGoLRUCache.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+                       tabWidth = 2;
+                       usesTabs = 0;
+               };
+               AD255F3A0735B15E00D424E6 = {
+                       fileEncoding = 5;
+                       indentWidth = 2;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = SOGoLRUCache.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+                       tabWidth = 2;
+               };
                AD2C74A1071A9FF70087E027 = {
                        fileEncoding = 5;
                        isa = PBXFileReference;
index 3ca73558577bb801e1b5074e177cacb9903e89dc..0716a19995afa7d361884a509145d8668d6d6dc4 100644 (file)
 
 #import <Foundation/Foundation.h>
 
+@class SOGoLRUCache;
 
 @interface AgenorUserManager : NSObject
 {
+  SOGoLRUCache *cnCache;
+  SOGoLRUCache *serverCache;
 }
 
 + (id)sharedUserManager;
index 158808276da818b112eb67518ae958ae7ebeefb6..94d1b91dbc635af3b53a0866ffbe38ac3f5dd542 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "AgenorUserManager.h"
 #include <NGLdap/NGLdap.h>
-
+#include "SOGoLRUCache.h"
 
 @interface AgenorUserManager (PrivateAPI)
 - (NGLdapConnection *)ldapConnection;
@@ -70,11 +70,15 @@ static NSString *ldapBaseDN = nil;
 - (id)init {
   self = [super init];
   if(self) {
+    self->serverCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
+    self->cnCache     = [[SOGoLRUCache alloc] initWithCacheSize:10000];
   }
   return self;
 }
 
 - (void)dealloc {
+  [self->serverCache release];
+  [self->cnCache     release];
   [super dealloc];
 }
 
@@ -90,17 +94,19 @@ static NSString *ldapBaseDN = nil;
 }
 
 - (void)_cacheCN:(NSString *)_cn forUID:(NSString *)_uid {
+  [self->cnCache addObject:_cn forKey:_uid];
 }
 
 - (NSString *)_cachedCNForUID:(NSString *)_uid {
-  return nil;
+  return [self->cnCache objectForKey:_uid];
 }
 
 - (void)_cacheServer:(NSString *)_server forUID:(NSString *)_uid {
+  [self->serverCache addObject:_server forKey:_uid];
 }
 
 - (NSString *)_cachedServerForUID:(NSString *)_uid {
-  return nil;
+  return [self->serverCache objectForKey:_uid];
 }
 
 
index 78bb6dd87d0e1100c492c7ff682fdd18ead93c46..76b8d4528a6cb3deca6dd5819847e48c554bf19c 100644 (file)
@@ -1,3 +1,14 @@
+2004-11-01  Marcus Mueller  <znek@mulle-kybernetik.com>
+
+       * v0.9.25
+
+       * SOGoLRUCache.[hm]: new class providing a generic cache for
+         objects used in SOGo. The cache is a LRU cache using a use count
+         to determined which objects are accessed most/least.
+
+       * AgenorUserManager.[hm]: uses SOGoLRUCache to cache CN's and
+         Servers.
+
 2004-10-20  Marcus Mueller  <znek@mulle-kybernetik.com>
 
        * AgenorUserManager.[hm]: slightly changed the interface for retrieving
index 76c923d519bc484142d20f1a43b781d587a44a30..71eae7f35e254030ac3b4a31ff7a6e35bbc0d912 100644 (file)
@@ -1,6 +1,7 @@
 # GNUstep Makefile
 
 include $(GNUSTEP_MAKEFILES)/common.make
+include ../SOGo/Version
 include ./Version
 
 LIBRARY_NAME = libSOGoLogic
@@ -13,11 +14,13 @@ libSOGoLogic_HEADER_FILES += \
        SOGoAppointment.h               \
        SOGoAppointmentICalRenderer.h   \
        AgenorUserManager.h             \
+       SOGoLRUCache.h                  \
        NSString+iCal.h
 
 libSOGoLogic_OBJC_FILES += \
        SOGoAppointment.m               \
        SOGoAppointmentICalRenderer.m   \
+       SOGoLRUCache.m                  \
        AgenorUserManager.m             \
 
 -include GNUmakefile.preamble
diff --git a/SOGoLogic/SOGoLRUCache.h b/SOGoLogic/SOGoLRUCache.h
new file mode 100644 (file)
index 0000000..1d29a50
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ Copyright (C) 2000-2004 SKYRIX Software AG
+ This file is part of OGo
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ License for more details.
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING.  If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+ */
+// $Id$
+
+
+#ifndef        __SOGoLRUCache_H_
+#define        __SOGoLRUCache_H_
+
+
+#import <Foundation/Foundation.h>
+
+
+@interface SOGoLRUCache : NSObject
+{
+  unsigned size;
+  NSMutableDictionary *entries;
+}
+
+- (id)initWithCacheSize:(unsigned)_size;
+
+- (void)addObject:(id)_obj forKey:(id)_key;
+- (id)objectForKey:(id)_key;
+
+@end
+
+#endif /* __SOGoLRUCache_H_ */
diff --git a/SOGoLogic/SOGoLRUCache.m b/SOGoLogic/SOGoLRUCache.m
new file mode 100644 (file)
index 0000000..dd11e77
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ Copyright (C) 2000-2004 SKYRIX Software AG
+ This file is part of OGo
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ License for more details.
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING.  If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+ */
+// $Id$
+
+
+#import "SOGoLRUCache.h"
+#import "common.h"
+
+@interface SOGoLRUCacheItem : NSObject
+{
+  id object;
+  unsigned useCount;
+}
+
+- (id)initWithObject:(id)_obj;
+- (id)object;
+
+- (unsigned)useCount;
+
+@end
+
+@implementation SOGoLRUCacheItem
+
+- (id)initWithObject:(id)_obj {
+  self = [super init];
+  if(self) {
+    ASSIGN(self->object, _obj);
+    self->useCount = 1;
+  }
+  return self;
+}
+
+- (id)object {
+  self->useCount++;
+  return self->object;
+}
+
+- (unsigned)useCount {
+  return self->useCount;
+}
+
+@end
+
+@implementation SOGoLRUCache
+
+- (id)initWithCacheSize:(unsigned)_size {
+  self = [super init];
+  if(self) {
+    self->size = _size;
+    self->entries = [[NSMutableDictionary alloc] initWithCapacity:_size];
+  }
+  return self;
+}
+
+- (void)dealloc {
+  [self->entries release];
+  [super dealloc];
+}
+
+- (void)addObject:(id)_obj forKey:(id)_key {
+  SOGoLRUCacheItem *item;
+
+  NSAssert(_obj, @"Attempt to insert nil object!");
+
+  if([self->entries count] >= self->size) {
+    /* need to find minimum and get rid of it */
+    NSEnumerator     *keyEnum;
+    SOGoLRUCacheItem *item;
+    id               key, leastUsedItemKey;
+    unsigned         minimumUseCount = INT_MAX;
+
+    keyEnum = [self->entries keyEnumerator];
+    while((key = [keyEnum nextObject])) {
+      item = [self->entries objectForKey:key];
+      if([item useCount] < minimumUseCount) {
+        minimumUseCount = [item useCount];
+        leastUsedItemKey = key;
+      }
+    }
+    [self->entries removeObjectForKey:leastUsedItemKey];
+  }
+  item = [[SOGoLRUCacheItem alloc] initWithObject:_obj];
+  [self->entries setObject:item forKey:_key];
+  [item release];
+}
+
+- (id)objectForKey:(id)_key {
+  SOGoLRUCacheItem *item;
+  
+  item = [self->entries objectForKey:_key];
+  if(!item)
+    return nil;
+  return [item object];
+}
+
+@end
index bd94857084a6dc664a6571b4e993119a2b48354d..6238c96506b08fb3fc85ed4410e575bb42a629b4 100644 (file)
@@ -1,6 +1,6 @@
 # Version file
 
-SUBMINOR_VERSION:=24
+SUBMINOR_VERSION:=25
 
 # v0.9.23 requires NGiCal        v4.3.32
 # v0.9.18 requires NGExtensions  v4.3.123