diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php
index ff47f08d485acfdc398a2b08394620120fa42076..71aa83073168a9c3121f158571c0a58482ebc77a 100644
--- a/lib/private/appconfig.php
+++ b/lib/private/appconfig.php
@@ -47,6 +47,10 @@ class AppConfig implements \OCP\IAppConfig {
 	 */
 	protected $conn;
 
+	private $cache = array();
+
+	private $appsLoaded = array();
+
 	/**
 	 * @param \OC\DB\Connection $conn
 	 */
@@ -54,6 +58,32 @@ class AppConfig implements \OCP\IAppConfig {
 		$this->conn = $conn;
 	}
 
+	/**
+	 * @param string $app
+	 * @return string[]
+	 */
+	private function getAppCache($app) {
+		if (!isset($this->cache[$app])) {
+			$this->cache[$app] = array();
+		}
+		return $this->cache[$app];
+	}
+
+	private function getAppValues($app) {
+		$appCache = $this->getAppCache($app);
+		if (array_search($app, $this->appsLoaded) === false) {
+			$query = 'SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
+				. ' WHERE `appid` = ?';
+			$result = $this->conn->executeQuery($query, array($app));
+			while ($row = $result->fetch()) {
+				$appCache[$row['configkey']] = $row['configvalue'];
+			}
+			$this->appsLoaded[] = $app;
+		}
+		$this->cache[$app] = $appCache;
+		return $appCache;
+	}
+
 	/**
 	 * @brief Get all apps using the config
 	 * @return array with app ids
@@ -81,15 +111,8 @@ class AppConfig implements \OCP\IAppConfig {
 	 * not returned.
 	 */
 	public function getKeys($app) {
-		$query = 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?';
-		$result = $this->conn->executeQuery($query, array($app));
-
-		$keys = array();
-		while ($key = $result->fetchColumn()) {
-			$keys[] = $key;
-		}
-
-		return $keys;
+		$values = $this->getAppValues($app);
+		return array_keys($values);
 	}
 
 	/**
@@ -103,11 +126,9 @@ class AppConfig implements \OCP\IAppConfig {
 	 * not exist the default value will be returned
 	 */
 	public function getValue($app, $key, $default = null) {
-		$query = 'SELECT `configvalue` FROM `*PREFIX*appconfig`'
-			. ' WHERE `appid` = ? AND `configkey` = ?';
-		$row = $this->conn->fetchAssoc($query, array($app, $key));
-		if ($row) {
-			return $row['configvalue'];
+		$values = $this->getAppValues($app);
+		if (isset($values[$key])) {
+			return $values[$key];
 		} else {
 			return $default;
 		}
@@ -120,8 +141,8 @@ class AppConfig implements \OCP\IAppConfig {
 	 * @return bool
 	 */
 	public function hasKey($app, $key) {
-		$exists = $this->getKeys($app);
-		return in_array($key, $exists);
+		$values = $this->getAppValues($app);
+		return isset($values[$key]);
 	}
 
 	/**
@@ -151,6 +172,10 @@ class AppConfig implements \OCP\IAppConfig {
 			);
 			$this->conn->update('*PREFIX*appconfig', $data, $where);
 		}
+		if (!isset($this->cache[$app])) {
+			$this->cache[$app] = array();
+		}
+		$this->cache[$app][$key] = $value;
 	}
 
 	/**
@@ -167,6 +192,9 @@ class AppConfig implements \OCP\IAppConfig {
 			'configkey' => $key,
 		);
 		$this->conn->delete('*PREFIX*appconfig', $where);
+		if (isset($this->cache[$app]) and isset($this->cache[$app][$key])) {
+			unset($this->cache[$app][$key]);
+		}
 	}
 
 	/**
@@ -181,6 +209,7 @@ class AppConfig implements \OCP\IAppConfig {
 			'appid' => $app,
 		);
 		$this->conn->delete('*PREFIX*appconfig', $where);
+		unset($this->cache[$app]);
 	}
 
 	/**
diff --git a/lib/private/db/statementwrapper.php b/lib/private/db/statementwrapper.php
index 5e89261d93637a70c1f5d2208483d1b6119906a7..a71df315e2fc55b0f1577806375cf0ef289fd5da 100644
--- a/lib/private/db/statementwrapper.php
+++ b/lib/private/db/statementwrapper.php
@@ -31,6 +31,9 @@ class OC_DB_StatementWrapper {
 
 	/**
 	 * make execute return the result instead of a bool
+	 *
+	 * @param array $input
+	 * @return \OC_DB_StatementWrapper | int
 	 */
 	public function execute($input=array()) {
 		if(OC_Config::getValue( "log_query", false)) {