Added client side caching. (Commited by: Jeff Costlow <j.costlow@f5.com>)

This commit is contained in:
Ralf Haferkamp 2001-05-04 14:38:13 +00:00
parent 0d41df6ff8
commit a2fe43daf9
10 changed files with 126 additions and 55 deletions

View file

@ -80,9 +80,9 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ./src/config.h CONFIG_HEADER = ./src/config.h
CONFIG_CLEAN_FILES = 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 \ 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) 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) $(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
cd $(srcdir) && $(AUTOCONF) 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 # This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile. # into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles, # To change the values of `make' variables: instead of editing Makefiles,
@ -269,7 +241,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \ @for file in $(DISTFILES); do \
d=$(srcdir); \ d=$(srcdir); \
if test -d $$d/$$file; then \ if test -d $$d/$$file; then \
cp -pr $$d/$$file $(distdir)/$$file; \ cp -pr $$/$$file $(distdir)/$$file; \
else \ else \
test -f $(distdir)/$$file \ test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \ || 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]* -rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic: maintainer-clean-generic:
mostlyclean-am: mostlyclean-hdr mostlyclean-tags mostlyclean-generic mostlyclean-am: mostlyclean-tags mostlyclean-generic
mostlyclean: mostlyclean-recursive mostlyclean: mostlyclean-recursive
clean-am: clean-hdr clean-tags clean-generic mostlyclean-am clean-am: clean-tags clean-generic mostlyclean-am
clean: clean-recursive clean: clean-recursive
distclean-am: distclean-hdr distclean-tags distclean-generic clean-am distclean-am: distclean-tags distclean-generic clean-am
-rm -f libtool -rm -f libtool
distclean: distclean-recursive distclean: distclean-recursive
-rm -f config.status -rm -f config.status
maintainer-clean-am: maintainer-clean-hdr maintainer-clean-tags \ maintainer-clean-am: maintainer-clean-tags maintainer-clean-generic \
maintainer-clean-generic distclean-am distclean-am
@echo "This command is intended for maintainers to use;" @echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild." @echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-recursive maintainer-clean: maintainer-clean-recursive
-rm -f config.status -rm -f config.status
.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ .PHONY: install-data-recursive uninstall-data-recursive \
install-data-recursive uninstall-data-recursive install-exec-recursive \ install-exec-recursive uninstall-exec-recursive installdirs-recursive \
uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \ uninstalldirs-recursive all-recursive check-recursive \
all-recursive check-recursive installcheck-recursive info-recursive \ installcheck-recursive info-recursive dvi-recursive \
dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \ mostlyclean-recursive distclean-recursive clean-recursive \
maintainer-clean-recursive tags tags-recursive mostlyclean-tags \ maintainer-clean-recursive tags tags-recursive mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \ distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \ dvi-am dvi check check-am installcheck-am installcheck install-exec-am \

View file

@ -35,6 +35,8 @@ LDAPAddRequest::LDAPAddRequest(const LDAPEntry* entry,
LDAPAddRequest::~LDAPAddRequest(){ LDAPAddRequest::~LDAPAddRequest(){
DEBUG(LDAP_DEBUG_DESTROY, "LDAPAddRequest::~LDAPAddRequest()" << endl); DEBUG(LDAP_DEBUG_DESTROY, "LDAPAddRequest::~LDAPAddRequest()" << endl);
delete m_entry; delete m_entry;
// flush the cache, as the add may affect searches
m_connection->flush_cache();
} }
LDAPMessageQueue* LDAPAddRequest::sendRequest(){ LDAPMessageQueue* LDAPAddRequest::sendRequest(){

View file

@ -36,6 +36,9 @@ LDAPAsynConnection::LDAPAsynConnection(const string& hostname, int port,
LDAPAsynConnection::~LDAPAsynConnection(){ LDAPAsynConnection::~LDAPAsynConnection(){
DEBUG(LDAP_DEBUG_DESTROY, DEBUG(LDAP_DEBUG_DESTROY,
"LDAPAsynConnection::~LDAPAsynConnection()" << endl); "LDAPAsynConnection::~LDAPAsynConnection()" << endl);
if (cur_session){
ldap_destroy_cache(cur_session);
}
unbind(); unbind();
//delete m_constr; //delete m_constr;
} }
@ -289,3 +292,26 @@ LDAPAsynConnection* LDAPAsynConnection::referralConnect(
return 0; 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);
}
}

View file

@ -283,7 +283,22 @@ class LDAPAsynConnection{
LDAPUrlList::const_iterator& usedUrl, LDAPUrlList::const_iterator& usedUrl,
const LDAPConstraints* cons) const; 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 :
/** /**
* Private copy constructor. So nobody can call it. * Private copy constructor. So nobody can call it.
@ -313,6 +328,11 @@ class LDAPAsynConnection{
*/ */
int m_port; int m_port;
protected:
/**
* Is caching enabled?
*/
bool m_cacheEnabled;
}; };
#endif //LDAP_ASYN_CONNECTION_H #endif //LDAP_ASYN_CONNECTION_H

View file

@ -18,17 +18,17 @@ typedef list<LDAPAttribute> AttrList;
* This container class is used to store multiple LDAPAttribute-objects. * This container class is used to store multiple LDAPAttribute-objects.
*/ */
class LDAPAttributeList{ class LDAPAttributeList{
private : private :
AttrList m_attrs; AttrList m_attrs;
public : public :
typedef AttrList::const_iterator const_iterator; typedef AttrList::const_iterator const_iterator;
/** /**
* Copy-constructor * Copy-constructor
*/ */
LDAPAttributeList(const LDAPAttributeList& al); LDAPAttributeList(const LDAPAttributeList& al);
/** /**
* For internal use only * For internal use only
@ -37,12 +37,12 @@ class LDAPAttributeList{
* list of attributes from a LDAPMessage-struct that was return by * list of attributes from a LDAPMessage-struct that was return by
* the C-API * the C-API
*/ */
LDAPAttributeList(const LDAPAsynConnection *ld, LDAPMessage *msg); LDAPAttributeList(const LDAPAsynConnection *ld, LDAPMessage *msg);
/** /**
* Constructs an empty list. * Constructs an empty list.
*/ */
LDAPAttributeList(); LDAPAttributeList();
/** /**
* Destructor * Destructor
@ -70,19 +70,19 @@ class LDAPAttributeList{
* Adds one element to the end of the list. * Adds one element to the end of the list.
* @param attr The attribute to add to 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 * Translates the list of Attributes to a 0-terminated array of
* LDAPMod-structures as needed by the C-API * 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. * This method can be used to dump the data of a LDAPResult-Object.
* It is only useful for debugging purposes at the moment * 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 #endif // LDAP_ATTRIBUTE_LIST_H

View file

@ -332,3 +332,30 @@ void LDAPConnection::setConstraints(LDAPConstraints* cons){
const LDAPConstraints* LDAPConnection::getConstraints() const{ const LDAPConstraints* LDAPConnection::getConstraints() const{
return LDAPAsynConnection::getConstraints(); 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();
}

View file

@ -229,6 +229,22 @@ class LDAPConnection : private LDAPAsynConnection {
void setConstraints(LDAPConstraints *cons); void setConstraints(LDAPConstraints *cons);
const LDAPConstraints* getConstraints() const ; 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 #endif //LDAP_CONNECTION_H

View file

@ -31,8 +31,11 @@ LDAPDeleteRequest::LDAPDeleteRequest(const string& dn,
} }
LDAPDeleteRequest::~LDAPDeleteRequest(){ LDAPDeleteRequest::~LDAPDeleteRequest(){
DEBUG(LDAP_DEBUG_DESTROY, DEBUG(LDAP_DEBUG_DESTROY,
"LDAPDeleteRequest::~LDAPDeleteRequest()" << endl); "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(){ LDAPMessageQueue* LDAPDeleteRequest::sendRequest(){

View file

@ -42,6 +42,9 @@ LDAPModDNRequest::LDAPModDNRequest(const string& dn, const string& newRDN,
LDAPModDNRequest::~LDAPModDNRequest(){ LDAPModDNRequest::~LDAPModDNRequest(){
DEBUG(LDAP_DEBUG_DESTROY, "LDAPModDNRequest::~LDAPModDNRequest()" << endl); 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(){ LDAPMessageQueue* LDAPModDNRequest::sendRequest(){

View file

@ -37,6 +37,8 @@ LDAPModifyRequest::~LDAPModifyRequest(){
DEBUG(LDAP_DEBUG_DESTROY, DEBUG(LDAP_DEBUG_DESTROY,
"LDAPModifyRequest::~LDAPModifyRequest()" << endl); "LDAPModifyRequest::~LDAPModifyRequest()" << endl);
delete m_modList; delete m_modList;
// flush this entry from cache.
m_connection->uncache_entry(m_dn);
} }
LDAPMessageQueue* LDAPModifyRequest::sendRequest(){ LDAPMessageQueue* LDAPModifyRequest::sendRequest(){