From 199ddd8e76edd04d6f62ef2e4672c693df17953b Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 7 Nov 2008 14:18:57 +0000 Subject: Refs #529: Experimental memcaching on datalists git-svn-id: https://code.elgg.org/elgg/trunk@2423 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'engine') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 836064060..addcf930e 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1506,9 +1506,20 @@ $name = sanitise_string($name); if (isset($DATALIST_CACHE[$name])) return $DATALIST_CACHE[$name]; + + // If memcache enabled then cache value in memcache + static $datalist_memcache; + if ((!$datalist_memcache) && (is_memcache_available())) + $datalist_memcache = new ElggMemcache('datalist_memcache'); + if ($datalist_memcache) $value = $datalist_memcache->load($name); + if ($value) return $value; if ($row = get_data_row("SELECT value from {$CONFIG->dbprefix}datalists where name = '{$name}' limit 1")) { - $DATALIST_CACHE[$name] = $row->value; + $DATALIST_CACHE[$name] = $row->value; + + // Cache it if memcache is available + if ($datalist_memcache) $datalist_memcache->save($name, $row-value); + return $row->value; } return false; @@ -1528,6 +1539,12 @@ $name = sanitise_string($name); $value = sanitise_string($value); + + // If memcache is available then invalidate the cached copy + static $datalist_memcache; + if ((!$datalist_memcache) && (is_memcache_available())) + $datalist_memcache = new ElggMemcache('datalist_memcache'); + if ($datalist_memcache) $value = $datalist_memcache->delete($name); //delete_data("delete from {$CONFIG->dbprefix}datalists where name = '{$name}'"); insert_data("INSERT into {$CONFIG->dbprefix}datalists set name = '{$name}', value = '{$value}' ON DUPLICATE KEY UPDATE value='{$value}'"); -- cgit v1.2.3