diff --git a/addressbook/e-book-backend-gal.c b/addressbook/e-book-backend-gal.c
index 4ab9b2c..e4a5494 100644
--- a/addressbook/e-book-backend-gal.c
+++ b/addressbook/e-book-backend-gal.c
@@ -93,6 +93,7 @@ struct _EBookBackendGALPrivate {
 	ExchangeAccount  *account;
 
 	gboolean marked_for_offline;
+	gboolean caching_now;
 	GMutex		*ldap_lock;
 
 	/* our operations */
@@ -1764,227 +1765,6 @@ get_contacts_from_cache (EBookBackendGAL *ebg,
 }
 #endif
 
-static void
-start_book_view (EBookBackend  *backend,
-		 EDataBookView *view)
-{
-	EBookBackendGAL *bl = E_BOOK_BACKEND_GAL (backend);
-	GNOME_Evolution_Addressbook_CallStatus status;
-	GList *contacts;
-	gchar *ldap_query;
-	gint ldap_err = LDAP_SUCCESS;
-	gint search_msgid;
-	gint view_limit;
-	GList *l;
-
-	d(printf("start book view\n"));
-	switch (bl->priv->mode) {
-	case GNOME_Evolution_Addressbook_MODE_LOCAL:
-#if ENABLE_CACHE
-		if (!(bl->priv->marked_for_offline && bl->priv->file_db)) {
-			e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_RepositoryOffline);
-			return;
-		}
-
-		contacts = e_book_backend_db_cache_get_contacts (bl->priv->file_db,
-							      e_data_book_view_get_card_query (view));
-
-		for (l = contacts; l; l = g_list_next (l)) {
-			EContact *contact = l->data;
-			e_data_book_view_notify_update (view, contact);
-			g_object_unref (contact);
-		}
-
-		g_list_free (contacts);
-
-		e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_Success);
-		return;
-#else
-		e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_RepositoryOffline);
-		return;
-#endif
-	case GNOME_Evolution_Addressbook_MODE_REMOTE:
-#if ENABLE_CACHE
-		d(printf("Mode:Remote\n"));
-		if (bl->priv->marked_for_offline && bl->priv->file_db) {
-			const gchar *query = e_data_book_view_get_card_query (view);
-			GPtrArray *ids = NULL;
-			d(printf("Marked for offline and cache present\n"));
-
-			status = build_query (bl, e_data_book_view_get_card_query (view), NULL,
-					      &ldap_query);
-
-			/* search for anything */
-			if (!ldap_query && (status == GNOME_Evolution_Addressbook_QueryRefused || status == GNOME_Evolution_Addressbook_Success) && can_browse ((EBookBackend *)bl)) {
-				ldap_query = g_strdup ("(mail=*)");
-				status = GNOME_Evolution_Addressbook_Success;
-			}
-
-			if (status != GNOME_Evolution_Addressbook_Success || !ldap_query) {
-				e_data_book_view_notify_complete (view, status);
-				if (ldap_query)
-					g_free (ldap_query);
-				return;
-			}
-
-			if (bl->priv->is_summary_ready &&
-			    e_book_backend_summary_is_summary_query (bl->priv->summary, query)) {
-				d(printf("Summary ready and summary_query, searching from summary \n"));
-				ids = e_book_backend_summary_search (bl->priv->summary, query);
-				if (ids && ids->len > 0) {
-					get_contacts_from_cache (bl, query, ids, view);
-					g_ptr_array_free (ids, TRUE);
-				}
-				return;
-			}
-
-			contacts = e_book_backend_db_cache_get_contacts (bl->priv->file_db,
-									 e_data_book_view_get_card_query (view));
-			for (l = contacts; l;l = g_list_next (l)) {
-				EContact *contact = l->data;
-				e_data_book_view_notify_update (view, contact);
-				g_object_unref (contact);
-			}
-
-			g_list_free (contacts);
-
-			e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_Success);
-			return;
-		}
-		else {
-#endif
-			if (!bl->priv->connected) {
-				e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_RepositoryOffline);
-				return;
-			}
-
-			d(printf("Not marked for offline or cache not there\n"));
-			g_mutex_lock (bl->priv->ldap_lock);
-			if (!bl->priv->ldap) {
-				g_mutex_unlock (bl->priv->ldap_lock);
-				if (!gal_reconnect (bl, view, 0)) {
-					d(printf("%s:%s: no ldap :(\n", G_STRLOC, G_STRFUNC));
-					e_data_book_view_notify_complete (view,
-									  GNOME_Evolution_Addressbook_InvalidQuery);
-					return;
-				}
-			}
-			g_mutex_unlock (bl->priv->ldap_lock);
-
-			/* we start at 1 so the user sees stuff as it appears and we
-			   aren't left waiting for more cards to show up, if the
-			   connection is slow. */
-			e_data_book_view_set_thresholds (view, 1, 3000);
-
-			view_limit = e_data_book_view_get_max_results (view);
-			if (view_limit == -1 || view_limit > bl->priv->gc->response_limit)
-				view_limit = bl->priv->gc->response_limit;
-
-			d(printf ("start_book_view (%p)\n", view));
-
-			status = build_query (bl, e_data_book_view_get_card_query (view), NULL,
-					      &ldap_query);
-
-			/* search for anything */
-			if (!ldap_query &&  (status == GNOME_Evolution_Addressbook_QueryRefused || status == GNOME_Evolution_Addressbook_Success) && can_browse ((EBookBackend *)bl)) {
-				ldap_query = g_strdup ("(mail=*)");
-				status = GNOME_Evolution_Addressbook_Success;
-			}
-
-			d(printf("%s:%s: %s\n", G_STRLOC, G_STRFUNC, ldap_query ? ldap_query : "No ldap_query produced!"));
-			if (status != GNOME_Evolution_Addressbook_Success || !ldap_query) {
-				e_data_book_view_notify_complete (view, status);
-				if (ldap_query)
-					g_free (ldap_query);
-				d(printf("%s:%s: failure \n", G_STRLOC, G_STRFUNC));
-				return;
-			}
-
-			do {
-				g_mutex_lock (bl->priv->ldap_lock);
-				if (bl->priv->ldap) {
-					g_mutex_unlock (bl->priv->ldap_lock);
-					book_view_notify_status (view, _("Searching..."));
-
-					g_mutex_lock (bl->priv->ldap_lock);
-					d(printf("%s:%s: starting \n", G_STRLOC, G_STRFUNC));
-					ldap_err = ldap_search_ext (bl->priv->ldap, get_gal_search_base (),
-								    LDAP_SCOPE_SUBTREE,
-								    ldap_query,
-								    (gchar **) search_attrs, 0,
-								    NULL, /* XXX */
-								    NULL, /* XXX */
-								    NULL, /* XXX timeout */
-								    view_limit,
-								    &search_msgid);
-					g_mutex_unlock (bl->priv->ldap_lock);
-					d(printf("%s:%s: %d\n", G_STRLOC, G_STRFUNC, ldap_err));
-				} else {
-					g_mutex_unlock (bl->priv->ldap_lock);
-					bl->priv->connected = FALSE;
-				}
-			} while (gal_reconnect (bl, view, ldap_err));
-
-			g_free (ldap_query);
-
-			if (ldap_err != LDAP_SUCCESS) {
-				d(printf("%s:%s: error\n", G_STRLOC, G_STRFUNC));
-				book_view_notify_status (view, ldap_err2string(ldap_err));
-				return;
-			}
-			else if (search_msgid == -1) {
-				d(printf("%s:%s: error\n", G_STRLOC, G_STRFUNC));
-				book_view_notify_status (view,
-							 _("Error performing search"));
-				return;
-			}
-			else {
-				LDAPSearchOp *op = g_new0 (LDAPSearchOp, 1);
-
-				d(printf ("adding search_op (%p, %d)\n", view, search_msgid));
-				op->view = view;
-				op->aborted = FALSE;
-
-				e_data_book_view_ref (view);
-
-				ldap_op_add ((LDAPOp*)op, E_BOOK_BACKEND (bl), NULL, view,
-					     0, search_msgid,
-					     ldap_search_handler, ldap_search_dtor);
-				d(printf("start_book_view: Setting op %p in book %p\n", op, view));
-				g_object_set_data (G_OBJECT (view), "EBookBackendGAL.BookView::search_op", op);
-			}
-#if ENABLE_CACHE
-		}
-#endif
-	}
-}
-
-static void
-stop_book_view (EBookBackend  *backend,
-		EDataBookView *view)
-{
-	LDAPSearchOp *op;
-
-	d(printf ("stop_book_view (%p)\n", view));
-
-	op = g_object_get_data (G_OBJECT (view), "EBookBackendGAL.BookView::search_op");
-	d(printf("STOP BOOK VIEW: Getting op %p from view %p\n", op, view));
-	if (op) {
-		op->aborted = TRUE;
-		ldap_op_finished ((LDAPOp*)op);
-		g_free (op);
-	}
-}
-
-static void
-get_changes (EBookBackend *backend,
-	     EDataBook    *book,
-	     guint32	   opid,
-	     const gchar   *change_id)
-{
-	/* FIXME: implement */
-}
-
 static gint pagedResults = 1;
 static ber_int_t pageSize = 1000;
 static ber_int_t entriesLeft = 0;
@@ -1996,60 +1776,6 @@ static gint npagedreferences;
 static gint npagedextended;
 static gint npagedpartial;
 
-/* Set server controls.  Add controls extra_c[0..count-1], if set. */
-static void
-tool_server_controls( LDAP *ld, LDAPControl *extra_c, gint count )
-{
-	gint i = 0, j, crit = 0, err;
-	LDAPControl c[3], **ctrls;
-
-	ctrls = (LDAPControl**) malloc(sizeof(c) + (count+1)*sizeof(LDAPControl*));
-	if ( ctrls == NULL ) {
-		fprintf( stderr, "No memory\n" );
-		exit( EXIT_FAILURE );
-	}
-
-	while ( count-- ) {
-		ctrls[i++] = extra_c++;
-	}
-	ctrls[i] = NULL;
-
-	err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
-
-	if ( err != LDAP_SUCCESS ) {
-		for ( j = 0; j < i; j++ ) {
-			if ( ctrls[j]->ldctl_iscritical ) crit = 1;
-		}
-		fprintf( stderr, "Could not set %scontrols\n",
-			crit ? "critical " : "" );
-	}
-
-	free( ctrls );
-	if ( crit ) {
-		exit( EXIT_FAILURE );
-	}
-}
-
-#if defined (SUNLDAP) || defined (G_OS_WIN32)
-static struct berval *
-ber_dupbv( struct berval *dst, struct berval *src )
-{
-	struct berval *tmp;
-
-	tmp = ber_bvdup(src);
-	if (!tmp)
-		return NULL;
-
-	dst->bv_len = tmp->bv_len;
-	dst->bv_val = tmp->bv_val;
-	tmp->bv_len = 0;
-	tmp->bv_val = NULL;
-	ber_bvfree (tmp);
-
-	return dst;
-}
-#endif
-
 static gint
 parse_page_control(
 	LDAP *ld,
@@ -2121,6 +1847,40 @@ parse_page_control(
 	return err;
 }
 
+/* Set server controls.  Add controls extra_c[0..count-1], if set. */
+static void
+tool_server_controls( LDAP *ld, LDAPControl *extra_c, gint count )
+{
+	gint i = 0, j, crit = 0, err;
+	LDAPControl c[3], **ctrls;
+
+	ctrls = (LDAPControl**) malloc(sizeof(c) + (count+1)*sizeof(LDAPControl*));
+	if ( ctrls == NULL ) {
+		fprintf( stderr, "No memory\n" );
+		exit( EXIT_FAILURE );
+	}
+
+	while ( count-- ) {
+		ctrls[i++] = extra_c++;
+	}
+	ctrls[i] = NULL;
+
+	err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
+
+	if ( err != LDAP_SUCCESS ) {
+		for ( j = 0; j < i; j++ ) {
+			if ( ctrls[j]->ldctl_iscritical ) crit = 1;
+		}
+		fprintf( stderr, "Could not set %scontrols\n",
+			crit ? "critical " : "" );
+	}
+
+	free( ctrls );
+	if ( crit ) {
+		exit( EXIT_FAILURE );
+	}
+}
+
 #if ENABLE_CACHE
 static gint dosearch(
 	EBookBackendGAL *bl,
@@ -2142,6 +1902,7 @@ static gint dosearch(
 	static gint count = 0;
 	gchar *ssize = getenv("LDAP_LIMIT");
 	gint size = 0;
+	EDataBookView *book_view;
 
 	if (ssize && *ssize)
 		size = atoi(ssize);
@@ -2168,7 +1929,8 @@ static gint dosearch(
 		{
 			EContact *contact;
 			const gchar *uid;
-
+			gchar *message = NULL;
+			
 			switch ( ldap_msgtype( msg ) ) {
 			case LDAP_RES_SEARCH_ENTRY:
 				count ++;
@@ -2188,6 +1950,15 @@ static gint dosearch(
 						printf("Updating contact with uid %s from the server\n", uid);
 				} else
 					printf("New contact with uid %s, add to the DB\n", uid);
+				if (!book_view) {
+					book_view = find_book_view (bl);
+					printf ("\nNo BOOK VIEW as yet");
+				}
+				if (count % 100 == 0) {
+					message = g_strdup_printf (_("Caching LDAP results for GAL...%d contacts done"), count);
+					book_view_notify_status (book_view, message);
+					g_free (message);
+				}
 				e_book_backend_db_cache_add_contact (bl->priv->file_db, contact);
 				e_book_backend_summary_add_contact (bl->priv->summary, contact);
 				g_object_unref (contact);
@@ -2337,6 +2108,294 @@ update_cache (EBookBackendGAL *gal)
 #endif
 
 static void
+start_book_view (EBookBackend  *backend,
+		 EDataBookView *view)
+{
+	EBookBackendGAL *bl = E_BOOK_BACKEND_GAL (backend);
+	GNOME_Evolution_Addressbook_CallStatus status;
+	EDataBookView *book_view;
+	GList *contacts;
+	gchar *ldap_query;
+	gint ldap_err = LDAP_SUCCESS;
+	gint search_msgid;
+	gint view_limit;
+	GList *l;
+	GConfClient *gc = gconf_client_get_default();
+	gint interval = gconf_client_get_int (gc, "/apps/evolution/addressbook/gal_cache_interval", NULL);
+
+	printf("start book view\n");
+	switch (bl->priv->mode) {
+	case GNOME_Evolution_Addressbook_MODE_LOCAL:
+#if ENABLE_CACHE
+		if (!(bl->priv->marked_for_offline && bl->priv->file_db)) {
+			e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_RepositoryOffline);
+			return;
+		}
+
+		contacts = e_book_backend_db_cache_get_contacts (bl->priv->file_db,
+							      e_data_book_view_get_card_query (view));
+
+		for (l = contacts; l; l = g_list_next (l)) {
+			EContact *contact = l->data;
+			e_data_book_view_notify_update (view, contact);
+			g_object_unref (contact);
+		}
+
+		g_list_free (contacts);
+
+		e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_Success);
+		return;
+#else
+		e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_RepositoryOffline);
+		return;
+#endif
+	case GNOME_Evolution_Addressbook_MODE_REMOTE:
+#if ENABLE_CACHE
+		printf("Mode:Remote\n");
+		
+//		if (bl->priv->marked_for_offline && !e_book_backend_db_cache_is_populated (bl->priv->file_db) && !bl->priv->caching_now) {
+		book_view = find_book_view (bl);
+		if (bl->priv->marked_for_offline) {
+			if (e_book_backend_db_cache_is_populated (bl->priv->file_db) && !bl->priv->caching_now) {
+				time_t t1, t2;
+				gint diff;
+
+				gchar *t = e_book_backend_db_cache_get_time (bl->priv->file_db);
+				d(printf("Cache is populated, check if refresh is required \n"));
+				if (t && *t)
+					t1 = atoi (t);
+				else
+					t1=0;
+				t2 = time (NULL);
+				diff = interval * 24 * 60 *60;
+				/* We have a day specified, then we cache it. */
+				if (!diff || t2 - t1 > diff) {
+					d(printf ("Cache older than specified period, refreshing \n"));
+					bl->priv->caching_now = TRUE;
+					book_view_notify_status (book_view, _("Updating LDAP results for GAL..."));
+					update_cache (bl);
+					bl->priv->caching_now = FALSE;
+				}
+				else
+					bl->priv->is_summary_ready= TRUE;
+			} else if (!bl->priv->caching_now) {
+				d(printf("Cache not there, generate cache\n"));
+				bl->priv->caching_now = TRUE;
+				if (book_view)
+					book_view_notify_status (book_view, _("Caching LDAP results for GAL..."));
+				else
+					g_print ("\n**********************NO BOOK VIEW*******************\n");
+				generate_cache(bl, NULL);
+				bl->priv->caching_now = FALSE;
+			}
+			if (book_view)
+				e_data_book_view_notify_complete (book_view, GNOME_Evolution_Addressbook_Success);
+//			e_data_book_respond_authenticate_user (book, opid, GNOME_Evolution_Addressbook_Success);
+//			return;
+		} else
+			g_print ("\n Now we got here**********%s", NULL);
+
+		if (bl->priv->marked_for_offline && bl->priv->file_db && !bl->priv->caching_now) {
+			const gchar *query = e_data_book_view_get_card_query (view);
+			GPtrArray *ids = NULL;
+			d(printf("Marked for offline and cache present\n"));
+
+			status = build_query (bl, e_data_book_view_get_card_query (view), NULL,
+					      &ldap_query);
+
+			/* search for anything */
+			if (!ldap_query && (status == GNOME_Evolution_Addressbook_QueryRefused || status == GNOME_Evolution_Addressbook_Success) && can_browse ((EBookBackend *)bl)) {
+				ldap_query = g_strdup ("(mail=*)");
+				status = GNOME_Evolution_Addressbook_Success;
+			}
+
+			if (status != GNOME_Evolution_Addressbook_Success || !ldap_query) {
+				e_data_book_view_notify_complete (view, status);
+				if (ldap_query)
+					g_free (ldap_query);
+				return;
+			}
+
+			if (bl->priv->is_summary_ready &&
+			    e_book_backend_summary_is_summary_query (bl->priv->summary, query)) {
+				d(printf("Summary ready and summary_query, searching from summary \n"));
+				ids = e_book_backend_summary_search (bl->priv->summary, query);
+				if (ids && ids->len > 0) {
+					get_contacts_from_cache (bl, query, ids, view);
+					g_ptr_array_free (ids, TRUE);
+				}
+				return;
+			}
+
+			contacts = e_book_backend_db_cache_get_contacts (bl->priv->file_db,
+									 e_data_book_view_get_card_query (view));
+			for (l = contacts; l;l = g_list_next (l)) {
+				EContact *contact = l->data;
+				e_data_book_view_notify_update (view, contact);
+				g_object_unref (contact);
+			}
+
+			g_list_free (contacts);
+
+			e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_Success);
+			return;
+		}
+		else {
+#endif
+			g_print ("\n****************STILL CACHING**********************");
+			if (!bl->priv->connected) {
+				e_data_book_view_notify_complete (view, GNOME_Evolution_Addressbook_RepositoryOffline);
+				return;
+			}
+
+			d(printf("Not marked for offline or cache not there\n"));
+			g_mutex_lock (bl->priv->ldap_lock);
+			if (!bl->priv->ldap) {
+				g_mutex_unlock (bl->priv->ldap_lock);
+				if (!gal_reconnect (bl, view, 0)) {
+					d(printf("%s:%s: no ldap :(\n", G_STRLOC, G_STRFUNC));
+					e_data_book_view_notify_complete (view,
+									  GNOME_Evolution_Addressbook_InvalidQuery);
+					return;
+				}
+			}
+			g_mutex_unlock (bl->priv->ldap_lock);
+
+			/* we start at 1 so the user sees stuff as it appears and we
+			   aren't left waiting for more cards to show up, if the
+			   connection is slow. */
+			e_data_book_view_set_thresholds (view, 1, 3000);
+
+			view_limit = e_data_book_view_get_max_results (view);
+			if (view_limit == -1 || view_limit > bl->priv->gc->response_limit)
+				view_limit = bl->priv->gc->response_limit;
+
+			d(printf ("start_book_view (%p)\n", view));
+
+			status = build_query (bl, e_data_book_view_get_card_query (view), NULL,
+					      &ldap_query);
+
+			/* search for anything */
+			if (!ldap_query &&  (status == GNOME_Evolution_Addressbook_QueryRefused || status == GNOME_Evolution_Addressbook_Success) && can_browse ((EBookBackend *)bl)) {
+				ldap_query = g_strdup ("(mail=*)");
+				status = GNOME_Evolution_Addressbook_Success;
+			}
+
+			d(printf("%s:%s: %s\n", G_STRLOC, G_STRFUNC, ldap_query ? ldap_query : "No ldap_query produced!"));
+			if (status != GNOME_Evolution_Addressbook_Success || !ldap_query) {
+				e_data_book_view_notify_complete (view, status);
+				if (ldap_query)
+					g_free (ldap_query);
+				d(printf("%s:%s: failure \n", G_STRLOC, G_STRFUNC));
+				return;
+			}
+
+			do {
+				g_mutex_lock (bl->priv->ldap_lock);
+				if (bl->priv->ldap) {
+					g_mutex_unlock (bl->priv->ldap_lock);
+					book_view_notify_status (view, _("Searching..."));
+
+					g_mutex_lock (bl->priv->ldap_lock);
+					d(printf("%s:%s: starting \n", G_STRLOC, G_STRFUNC));
+					ldap_err = ldap_search_ext (bl->priv->ldap, get_gal_search_base (),
+								    LDAP_SCOPE_SUBTREE,
+								    ldap_query,
+								    (gchar **) search_attrs, 0,
+								    NULL, /* XXX */
+								    NULL, /* XXX */
+								    NULL, /* XXX timeout */
+								    view_limit,
+								    &search_msgid);
+					g_mutex_unlock (bl->priv->ldap_lock);
+					d(printf("%s:%s: %d\n", G_STRLOC, G_STRFUNC, ldap_err));
+				} else {
+					g_mutex_unlock (bl->priv->ldap_lock);
+					bl->priv->connected = FALSE;
+				}
+			} while (gal_reconnect (bl, view, ldap_err));
+
+			g_free (ldap_query);
+
+			if (ldap_err != LDAP_SUCCESS) {
+				d(printf("%s:%s: error\n", G_STRLOC, G_STRFUNC));
+				book_view_notify_status (view, ldap_err2string(ldap_err));
+				return;
+			}
+			else if (search_msgid == -1) {
+				d(printf("%s:%s: error\n", G_STRLOC, G_STRFUNC));
+				book_view_notify_status (view,
+							 _("Error performing search"));
+				return;
+			}
+			else {
+				LDAPSearchOp *op = g_new0 (LDAPSearchOp, 1);
+
+				d(printf ("adding search_op (%p, %d)\n", view, search_msgid));
+				op->view = view;
+				op->aborted = FALSE;
+
+				e_data_book_view_ref (view);
+
+				ldap_op_add ((LDAPOp*)op, E_BOOK_BACKEND (bl), NULL, view,
+					     0, search_msgid,
+					     ldap_search_handler, ldap_search_dtor);
+				d(printf("start_book_view: Setting op %p in book %p\n", op, view));
+				g_object_set_data (G_OBJECT (view), "EBookBackendGAL.BookView::search_op", op);
+			}
+#if ENABLE_CACHE
+		}
+#endif
+	}
+}
+
+static void
+stop_book_view (EBookBackend  *backend,
+		EDataBookView *view)
+{
+	LDAPSearchOp *op;
+
+	d(printf ("stop_book_view (%p)\n", view));
+
+	op = g_object_get_data (G_OBJECT (view), "EBookBackendGAL.BookView::search_op");
+	d(printf("STOP BOOK VIEW: Getting op %p from view %p\n", op, view));
+	if (op) {
+		op->aborted = TRUE;
+		ldap_op_finished ((LDAPOp*)op);
+		g_free (op);
+	}
+}
+
+static void
+get_changes (EBookBackend *backend,
+	     EDataBook    *book,
+	     guint32	   opid,
+	     const gchar   *change_id)
+{
+	/* FIXME: implement */
+}
+
+#if defined (SUNLDAP) || defined (G_OS_WIN32)
+static struct berval *
+ber_dupbv( struct berval *dst, struct berval *src )
+{
+	struct berval *tmp;
+
+	tmp = ber_bvdup(src);
+	if (!tmp)
+		return NULL;
+
+	dst->bv_len = tmp->bv_len;
+	dst->bv_val = tmp->bv_val;
+	tmp->bv_len = 0;
+	tmp->bv_val = NULL;
+	ber_bvfree (tmp);
+
+	return dst;
+}
+#endif
+
+static void
 authenticate_user (EBookBackend *backend,
 		   EDataBook    *book,
 		   guint32       opid,
@@ -2346,6 +2405,7 @@ authenticate_user (EBookBackend *backend,
 {
 	EBookBackendGAL *be = E_BOOK_BACKEND_GAL (backend);
 	EBookBackendGALPrivate *bepriv = be->priv;
+	EDataBookView *book_view;
 	ExchangeAccountResult result;
 	ExchangeAccount *account = NULL;
 	GNOME_Evolution_Addressbook_CallStatus res;
@@ -2370,6 +2430,9 @@ authenticate_user (EBookBackend *backend,
 
 	case GNOME_Evolution_Addressbook_MODE_REMOTE:
 
+		if (be->priv->caching_now) 
+			goto cleanup;
+
 		account = exchange_share_config_listener_get_account_for_uri (NULL, bepriv->gal_uri);
 		/* FIXME : Check for failures */
 		if (!exchange_account_get_context (account)) {
@@ -2386,37 +2449,9 @@ authenticate_user (EBookBackend *backend,
 			e_data_book_respond_authenticate_user (book, opid, res);
 			return;
 		}
-#if ENABLE_CACHE
-		if (be->priv->marked_for_offline) {
-			if (e_book_backend_db_cache_is_populated (be->priv->file_db) ) {
-				time_t t1, t2;
-				gint diff;
 
-				gchar *t = e_book_backend_db_cache_get_time (be->priv->file_db);
-				d(printf("Cache is populated, check if refresh is required \n"));
-				if (t && *t)
-					t1 = atoi (t);
-				else
-					t1=0;
-				t2 = time (NULL);
-				diff = interval * 24 * 60 *60;
-				/* We have a day specified, then we cache it. */
-				//if (!diff || t2 - t1 > diff) {
-				//	d(printf ("Cache older than specified period, refreshing \n"));
-					update_cache (be);
-				//}
-				//else
-				//	be->priv->is_summary_ready= TRUE;
-			}
-			else {
-				d(printf("Cache not there, generate cache\n"));
-				generate_cache(be, NULL);
-			}
-		}
-#endif
 		e_data_book_respond_authenticate_user (book, opid, GNOME_Evolution_Addressbook_Success);
 		return;
-
 	default:
 		break;
 	}
@@ -2425,6 +2460,7 @@ authenticate_user (EBookBackend *backend,
 	e_data_book_respond_authenticate_user (book,
 					       opid,
 					       GNOME_Evolution_Addressbook_UnsupportedAuthenticationMethod);
+cleanup:	
 	return;
 }
 
@@ -2576,6 +2612,8 @@ load_source (EBookBackend *backend,
 	g_object_unref (gc);
 	g_return_val_if_fail (bl->priv->connected == FALSE, GNOME_Evolution_Addressbook_OtherError);
 
+	bl->priv->caching_now = FALSE;
+
 	offline = e_source_get_property (source, "offline_sync");
 	if (offline && g_str_equal (offline, "1"))
 		bl->priv->marked_for_offline = TRUE;

