summaryrefslogtreecommitdiffstats
path: root/web/lib/cachefuncs.inc.php
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2019-10-06 18:59:34 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2019-10-06 22:13:38 +0200
commit1283fe4918adb369432ea2acc378610a3d5142a9 (patch)
tree51e99ed1cccae85823213049fe81a9ab00e43a76 /web/lib/cachefuncs.inc.php
parentef8bad5bbfa208daf3496dccd16c14577ba5607b (diff)
downloadaur-1283fe4918adb369432ea2acc378610a3d5142a9.tar.gz
aur-1283fe4918adb369432ea2acc378610a3d5142a9.tar.xz
Cache package provider and dependency information
The package provider and dependency queries are quite CPU-intensive and usually yield rather small result sets. Cache these values if the global caching mechanism is enabled. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web/lib/cachefuncs.inc.php')
-rw-r--r--web/lib/cachefuncs.inc.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/web/lib/cachefuncs.inc.php b/web/lib/cachefuncs.inc.php
index 881ad8f2..b2b96c24 100644
--- a/web/lib/cachefuncs.inc.php
+++ b/web/lib/cachefuncs.inc.php
@@ -79,4 +79,21 @@ function db_cache_value($dbq, $key, $ttl=600) {
return $value;
}
+# Run a simple db query, retrieving and/or caching the result set if APC is
+# available for use. Accepts an optional TTL value (defaults to 600 seconds).
+function db_cache_result($dbq, $key, $fetch_style=PDO::FETCH_NUM, $ttl=600) {
+ $dbh = DB::connect();
+ $status = false;
+ $value = get_cache_value($key, $status);
+ if (!$status) {
+ $result = $dbh->query($dbq);
+ if (!$result) {
+ return false;
+ }
+ $value = $result->fetchAll($fetch_style);
+ set_cache_value($key, $value, $ttl);
+ }
+ return $value;
+}
+
?>