From: Ralf Haferkamp Date: Fri, 4 May 2001 14:38:13 +0000 (+0000) Subject: Added client side caching. (Commited by: Jeff Costlow ) X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1445 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a2fe43daf971eddc2a757ac99e9bd9982a04497f;p=openldap Added client side caching. (Commited by: Jeff Costlow ) --- diff --git a/contrib/ldapc++/Makefile.in b/contrib/ldapc++/Makefile.in index b9a673d6d1..6fd70d7132 100644 --- a/contrib/ldapc++/Makefile.in +++ b/contrib/ldapc++/Makefile.in @@ -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 \ diff --git a/contrib/ldapc++/src/LDAPAddRequest.cpp b/contrib/ldapc++/src/LDAPAddRequest.cpp index f92e233b05..c1cf40dd7b 100644 --- a/contrib/ldapc++/src/LDAPAddRequest.cpp +++ b/contrib/ldapc++/src/LDAPAddRequest.cpp @@ -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(){ diff --git a/contrib/ldapc++/src/LDAPAsynConnection.cpp b/contrib/ldapc++/src/LDAPAsynConnection.cpp index 79223c94e4..585d2fa67b 100644 --- a/contrib/ldapc++/src/LDAPAsynConnection.cpp +++ b/contrib/ldapc++/src/LDAPAsynConnection.cpp @@ -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); + } +} diff --git a/contrib/ldapc++/src/LDAPAsynConnection.h b/contrib/ldapc++/src/LDAPAsynConnection.h index 1b3edf497e..d1842f263c 100644 --- a/contrib/ldapc++/src/LDAPAsynConnection.h +++ b/contrib/ldapc++/src/LDAPAsynConnection.h @@ -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 diff --git a/contrib/ldapc++/src/LDAPAttributeList.h b/contrib/ldapc++/src/LDAPAttributeList.h index 5cbe8f55f4..a2f3dd655d 100644 --- a/contrib/ldapc++/src/LDAPAttributeList.h +++ b/contrib/ldapc++/src/LDAPAttributeList.h @@ -18,17 +18,17 @@ typedef list 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 diff --git a/contrib/ldapc++/src/LDAPConnection.cpp b/contrib/ldapc++/src/LDAPConnection.cpp index cc8d713d49..8f9b583077 100644 --- a/contrib/ldapc++/src/LDAPConnection.cpp +++ b/contrib/ldapc++/src/LDAPConnection.cpp @@ -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(); +} + diff --git a/contrib/ldapc++/src/LDAPConnection.h b/contrib/ldapc++/src/LDAPConnection.h index c40b444318..0be90837c4 100644 --- a/contrib/ldapc++/src/LDAPConnection.h +++ b/contrib/ldapc++/src/LDAPConnection.h @@ -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 diff --git a/contrib/ldapc++/src/LDAPDeleteRequest.cpp b/contrib/ldapc++/src/LDAPDeleteRequest.cpp index 0cc34e6ac1..1e914bc0da 100644 --- a/contrib/ldapc++/src/LDAPDeleteRequest.cpp +++ b/contrib/ldapc++/src/LDAPDeleteRequest.cpp @@ -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(){ diff --git a/contrib/ldapc++/src/LDAPModDNRequest.cpp b/contrib/ldapc++/src/LDAPModDNRequest.cpp index 0977e9b9c2..68dbe2a2a7 100644 --- a/contrib/ldapc++/src/LDAPModDNRequest.cpp +++ b/contrib/ldapc++/src/LDAPModDNRequest.cpp @@ -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(){ diff --git a/contrib/ldapc++/src/LDAPModifyRequest.cpp b/contrib/ldapc++/src/LDAPModifyRequest.cpp index 7e8f41de86..69e9906022 100644 --- a/contrib/ldapc++/src/LDAPModifyRequest.cpp +++ b/contrib/ldapc++/src/LDAPModifyRequest.cpp @@ -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(){