]> git.sur5r.net Git - openldap/commitdiff
Added client side caching. (Commited by: Jeff Costlow <j.costlow@f5.com>)
authorRalf Haferkamp <ralf@openldap.org>
Fri, 4 May 2001 14:38:13 +0000 (14:38 +0000)
committerRalf Haferkamp <ralf@openldap.org>
Fri, 4 May 2001 14:38:13 +0000 (14:38 +0000)
contrib/ldapc++/Makefile.in
contrib/ldapc++/src/LDAPAddRequest.cpp
contrib/ldapc++/src/LDAPAsynConnection.cpp
contrib/ldapc++/src/LDAPAsynConnection.h
contrib/ldapc++/src/LDAPAttributeList.h
contrib/ldapc++/src/LDAPConnection.cpp
contrib/ldapc++/src/LDAPConnection.h
contrib/ldapc++/src/LDAPDeleteRequest.cpp
contrib/ldapc++/src/LDAPModDNRequest.cpp
contrib/ldapc++/src/LDAPModifyRequest.cpp

index b9a673d6d1f569b9b880f0abed8df9bbc229565a..6fd70d7132d542d22f86fbeb5e7a6fca5d7beb85 100644 (file)
@@ -80,9 +80,9 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
 CONFIG_HEADER = ./src/config.h
 CONFIG_CLEAN_FILES = 
-DIST_COMMON =  README AUTHORS Makefile.am Makefile.in TODO acconfig.h \
+DIST_COMMON =  README AUTHORS INSTALL Makefile.am Makefile.in TODO \
 aclocal.m4 config.guess config.sub configure configure.in install-sh \
-ltconfig ltmain.sh missing mkinstalldirs src/config.h.in src/stamp-h.in
+ltconfig ltmain.sh missing mkinstalldirs
 
 
 DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
@@ -106,34 +106,6 @@ config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 $(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
        cd $(srcdir) && $(AUTOCONF)
 
-src/config.h: src/stamp-h
-       @if test ! -f $@; then \
-               rm -f src/stamp-h; \
-               $(MAKE) src/stamp-h; \
-       else :; fi
-src/stamp-h: $(srcdir)/src/config.h.in $(top_builddir)/config.status
-       cd $(top_builddir) \
-         && CONFIG_FILES= CONFIG_HEADERS=src/config.h \
-            $(SHELL) ./config.status
-       @echo timestamp > src/stamp-h 2> /dev/null
-$(srcdir)/src/config.h.in: $(srcdir)/src/stamp-h.in
-       @if test ! -f $@; then \
-               rm -f $(srcdir)/src/stamp-h.in; \
-               $(MAKE) $(srcdir)/src/stamp-h.in; \
-       else :; fi
-$(srcdir)/src/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h
-       cd $(top_srcdir) && $(AUTOHEADER)
-       @echo timestamp > $(srcdir)/src/stamp-h.in 2> /dev/null
-
-mostlyclean-hdr:
-
-clean-hdr:
-
-distclean-hdr:
-       -rm -f src/config.h
-
-maintainer-clean-hdr:
-
 # This directory's subdirectories are mostly independent; you can cd
 # into them and run `make' without going through this Makefile.
 # To change the values of `make' variables: instead of editing Makefiles,
@@ -269,7 +241,7 @@ distdir: $(DISTFILES)
        @for file in $(DISTFILES); do \
          d=$(srcdir); \
          if test -d $$d/$$file; then \
-           cp -pr $$d/$$file $(distdir)/$$file; \
+           cp -pr $$/$$file $(distdir)/$$file; \
          else \
            test -f $(distdir)/$$file \
            || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
@@ -322,33 +294,33 @@ distclean-generic:
        -rm -f config.cache config.log stamp-h stamp-h[0-9]*
 
 maintainer-clean-generic:
-mostlyclean-am:  mostlyclean-hdr mostlyclean-tags mostlyclean-generic
+mostlyclean-am:  mostlyclean-tags mostlyclean-generic
 
 mostlyclean: mostlyclean-recursive
 
-clean-am:  clean-hdr clean-tags clean-generic mostlyclean-am
+clean-am:  clean-tags clean-generic mostlyclean-am
 
 clean: clean-recursive
 
-distclean-am:  distclean-hdr distclean-tags distclean-generic clean-am
+distclean-am:  distclean-tags distclean-generic clean-am
        -rm -f libtool
 
 distclean: distclean-recursive
        -rm -f config.status
 
-maintainer-clean-am:  maintainer-clean-hdr maintainer-clean-tags \
-               maintainer-clean-generic distclean-am
+maintainer-clean-am:  maintainer-clean-tags maintainer-clean-generic \
+               distclean-am
        @echo "This command is intended for maintainers to use;"
        @echo "it deletes files that may require special tools to rebuild."
 
 maintainer-clean: maintainer-clean-recursive
        -rm -f config.status
 
-.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \
-install-data-recursive uninstall-data-recursive install-exec-recursive \
-uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \
-all-recursive check-recursive installcheck-recursive info-recursive \
-dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \
+.PHONY: install-data-recursive uninstall-data-recursive \
+install-exec-recursive uninstall-exec-recursive installdirs-recursive \
+uninstalldirs-recursive all-recursive check-recursive \
+installcheck-recursive info-recursive dvi-recursive \
+mostlyclean-recursive distclean-recursive clean-recursive \
 maintainer-clean-recursive tags tags-recursive mostlyclean-tags \
 distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
 dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
index f92e233b055e4f1712b4335ec355e47fa44201e1..c1cf40dd7bd79ffa1fae52504e9047fe9f735615 100644 (file)
@@ -35,6 +35,8 @@ LDAPAddRequest::LDAPAddRequest(const LDAPEntry* entry,
 LDAPAddRequest::~LDAPAddRequest(){
     DEBUG(LDAP_DEBUG_DESTROY, "LDAPAddRequest::~LDAPAddRequest()" << endl);
     delete m_entry;
+    // flush the cache, as the add may affect searches
+    m_connection->flush_cache();
 }
 
 LDAPMessageQueue* LDAPAddRequest::sendRequest(){
index 79223c94e48f2ad2427dcae55cec3c5c28ff1167..585d2fa67b9de5f824674a91a682d4433e4c4a32 100644 (file)
@@ -36,6 +36,9 @@ LDAPAsynConnection::LDAPAsynConnection(const string& hostname, int port,
 LDAPAsynConnection::~LDAPAsynConnection(){
     DEBUG(LDAP_DEBUG_DESTROY,
             "LDAPAsynConnection::~LDAPAsynConnection()" << endl);
+    if (cur_session){
+        ldap_destroy_cache(cur_session);
+    }    
     unbind();
     //delete m_constr;        
 }
@@ -289,3 +292,26 @@ LDAPAsynConnection* LDAPAsynConnection::referralConnect(
     return 0;
 }
 
+int LDAPAsynConnection::enableCache(long timeout, long maxmem){
+    int retval = ldap_enable_cache(cur_session, timeout, maxmem);
+    if (!retval)
+        m_cacheEnabled = true;
+    return retval;    
+}    
+
+void LDAPAsynConnection::disableCache(){
+    ldap_disable_cache(cur_session);
+    m_cacheEnabled = false;
+}
+
+void LDAPAsynConnection::uncache_entry(string &dn){
+    if (m_cacheEnabled){
+        ldap_uncache_entry(cur_session, dn.c_str());
+    }
+}
+
+void LDAPAsynConnection::flush_cache(){
+    if (m_cacheEnabled){
+        ldap_flush_cache(cur_session);
+    }
+}
index 1b3edf497ed0f20b5de19f289abad6af1a061330..d1842f263cb0eb14beae847fc0690166384a0172 100644 (file)
@@ -283,7 +283,22 @@ class LDAPAsynConnection{
                 LDAPUrlList::const_iterator& usedUrl,
                 const LDAPConstraints* cons) const;
 
-
+        /**
+         * Turn on caching, maxmem is in MB and timeout is in seconds.
+         * maxmem can be zero if you want to restrict caching by timeout only.
+         */
+        int enableCache(long timeout, long maxmem);
+        /// disable caching.
+        void disableCache();
+        /// is cacheEnabled?
+        bool getCacheEnabled() { return m_cacheEnabled;};
+        /// uncache a specific dn.  Used internally by methods that write.
+        void uncache_entry(string &dn);
+        /// used to clear the cache.  Probably should be used after creating
+        /// an object that a cached search should find.
+        void flush_cache();
+        
+        
     private :
         /**
          * Private copy constructor. So nobody can call it.
@@ -313,6 +328,11 @@ class LDAPAsynConnection{
          */
         int m_port;
 
+ protected:
+        /**
+         * Is caching enabled?
+         */
+        bool m_cacheEnabled;
 };
 #endif //LDAP_ASYN_CONNECTION_H
 
index 5cbe8f55f4132d68b536a566291548150794f2e2..a2f3dd655df710f28db66b5b83a2c56243e557a3 100644 (file)
@@ -18,17 +18,17 @@ typedef list<LDAPAttribute> AttrList;
  * This container class is used to store multiple LDAPAttribute-objects.
  */
 class LDAPAttributeList{
-       private :
-               AttrList m_attrs;
+    private :
+        AttrList m_attrs;
 
-       public :
-               typedef AttrList::const_iterator const_iterator;
+    public :
+        typedef AttrList::const_iterator const_iterator;
 
 
         /**
          * Copy-constructor
          */
-               LDAPAttributeList(const LDAPAttributeList& al);
+        LDAPAttributeList(const LDAPAttributeList& al);
         
         /**
          * For internal use only
@@ -37,12 +37,12 @@ class LDAPAttributeList{
          * list of attributes from a LDAPMessage-struct that was return by
          * the C-API
          */
-               LDAPAttributeList(const LDAPAsynConnection *ld, LDAPMessage *msg);
+        LDAPAttributeList(const LDAPAsynConnection *ld, LDAPMessage *msg);
 
         /**
          * Constructs an empty list.
          */   
-               LDAPAttributeList();
+        LDAPAttributeList();
 
         /**
          * Destructor
@@ -70,19 +70,19 @@ class LDAPAttributeList{
          * Adds one element to the end of the list.
          * @param attr The attribute to add to the list.
          */
-               void addAttribute(const LDAPAttribute& attr);
+        void addAttribute(const LDAPAttribute& attr);
 
         /**
          * Translates the list of Attributes to a 0-terminated array of
          * LDAPMod-structures as needed by the C-API
          */
-               LDAPMod** toLDAPModArray() const;
-               
+        LDAPMod** toLDAPModArray() const;
+        
         /**
          * This method can be used to dump the data of a LDAPResult-Object.
          * It is only useful for debugging purposes at the moment
          */
-               friend ostream& operator << (ostream& s, const LDAPAttributeList& al);
+        friend ostream& operator << (ostream& s, const LDAPAttributeList& al);
 };
 #endif // LDAP_ATTRIBUTE_LIST_H
 
index cc8d713d49277aa486d2e8c449efa0b5f54b2ea8..8f9b5830779a72696dbd5ff27ab242a49bcc3226 100644 (file)
@@ -332,3 +332,30 @@ void LDAPConnection::setConstraints(LDAPConstraints* cons){
 const LDAPConstraints* LDAPConnection::getConstraints() const{
     return LDAPAsynConnection::getConstraints();
 }
+
+int LDAPConnection::enableCache(long timeout, long maxmem)
+{
+    return LDAPAsynConnection::enableCache(timeout, maxmem);
+}
+
+
+void LDAPConnection::disableCache()
+{
+    LDAPAsynConnection::disableCache();
+}
+
+bool LDAPConnection::getCacheEnabled()
+{ 
+    return LDAPAsynConnection::getCacheEnabled();
+}
+
+void LDAPConnection::uncache_entry(string &dn)
+{
+    LDAPAsynConnection::uncache_entry(dn);
+}
+
+void LDAPConnection::flush_cache()
+{
+    LDAPAsynConnection::flush_cache();
+}
+
index c40b4443186ca9cba95460fbcce50f2984ad5ab1..0be90837c420284a9b4a9e2cab3237ef805ab2dd 100644 (file)
@@ -229,6 +229,22 @@ class LDAPConnection : private LDAPAsynConnection {
         void setConstraints(LDAPConstraints *cons);
         
         const LDAPConstraints* getConstraints() const ;
+
+        /**
+         * Turn on caching, maxmem is in MB and timeout is in seconds.
+         * maxmem can be zero if you want to restrict caching by timeout only.
+         */
+        int enableCache(long timeout, long maxmem);
+        /// disable caching.
+        void disableCache();
+        /// is cacheEnabled?
+        bool getCacheEnabled();
+        /// uncache a specific dn.  Used internally by methods that write.
+        void uncache_entry(string &dn);
+        /// used to clear the cache.  Probably should be used after creating
+        /// an object that a cached search should find.
+        void flush_cache();
+
 };
 
 #endif //LDAP_CONNECTION_H
index 0cc34e6ac1becdc7a4a958c7052f2eda494b46af..1e914bc0dac51a7fe866c1003cbc755797df9678 100644 (file)
@@ -31,8 +31,11 @@ LDAPDeleteRequest::LDAPDeleteRequest(const string& dn,
 }
 
 LDAPDeleteRequest::~LDAPDeleteRequest(){
-       DEBUG(LDAP_DEBUG_DESTROY,
-            "LDAPDeleteRequest::~LDAPDeleteRequest()" << endl);
+    DEBUG(LDAP_DEBUG_DESTROY,
+          "LDAPDeleteRequest::~LDAPDeleteRequest()" << endl);
+    // TODO -- flush the entire cache here?  or does this invalidate
+    // cached searches that may have found the deleted entry.
+    m_connection->uncache_entry(m_dn);
 }
 
 LDAPMessageQueue* LDAPDeleteRequest::sendRequest(){
index 0977e9b9c2af5761ca61d9cf27b83f26af2db8d6..68dbe2a2a7e6d4fb56fff8e7739391e303cb307f 100644 (file)
@@ -42,6 +42,9 @@ LDAPModDNRequest::LDAPModDNRequest(const string& dn, const string& newRDN,
 
 LDAPModDNRequest::~LDAPModDNRequest(){
     DEBUG(LDAP_DEBUG_DESTROY, "LDAPModDNRequest::~LDAPModDNRequest()" << endl);
+    // flush entries from the cache.
+    m_connection->uncache_entry(m_dn);
+    m_connection->uncache_entry(m_newRDN);
 }
 
 LDAPMessageQueue* LDAPModDNRequest::sendRequest(){
index 7e8f41de86d66faddebd72da3359b6ba19880df6..69e9906022cc017646ddff7ea9bf866f1ad5c813 100644 (file)
@@ -37,6 +37,8 @@ LDAPModifyRequest::~LDAPModifyRequest(){
     DEBUG(LDAP_DEBUG_DESTROY, 
             "LDAPModifyRequest::~LDAPModifyRequest()" << endl);
     delete m_modList;
+    // flush this entry from cache.
+    m_connection->uncache_entry(m_dn);
 }
 
 LDAPMessageQueue* LDAPModifyRequest::sendRequest(){