diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index f05c8fb8ca4df6734b6a03dad10faf1a421cf0d0..b7d1b0d62b8ebde958664f449b45a62ba360b1ec 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -842,6 +842,9 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
 			return $groupUsers;
 		}
 
+		if ($limit === -1) {
+			$limit = null;
+		}
 		// check for cache of the query without limit and offset
 		$groupUsers = $this->access->connection->getFromCache('usersInGroup-' . $gid . '-' . $search);
 		if (!is_null($groupUsers)) {
@@ -850,9 +853,6 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
 			return $groupUsers;
 		}
 
-		if ($limit === -1) {
-			$limit = null;
-		}
 		$groupDN = $this->access->groupname2dn($gid);
 		if (!$groupDN) {
 			// group couldn't be found, return empty resultset