From b8d457e1523b9f76abcea4ca8c0de8d8f91765f0 Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 7 Nov 2008 12:30:35 +0000 Subject: Refs #529: Experimental caching of metastrings git-svn-id: https://code.elgg.org/elgg/trunk@2420 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/metastrings.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'engine') diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index 786e343ce..00728b1d3 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -41,10 +41,20 @@ if (in_array($string, $METASTRINGS_DEADNAME_CACHE)) return false; + // Experimental memcache + static $metastrings_memcache; + if ((!$metastrings_memcache) && (is_memcache_available())) + $metastrings_memcache = new ElggMemcache('metastrings_memcache'); + if ($metastrings_memcache) $msfc = $metastrings_memcache->load($string); + if ($msfc) return $msfc; + $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where string='$string' limit 1"); if ($row) { $METASTRINGS_CACHE[$row->id] = $row->string; // Cache it + // Attempt to memcache it if memcache is available + if ($metastrings_memcache) $metastrings_memcache->save($row->string, $row->id); + if (isset($CONFIG->debug) && $CONFIG->debug) error_log("** Cacheing string '{$row->string}'"); @@ -123,6 +133,30 @@ { global $CONFIG; + // If memcache is enabled then we need to flush it of deleted values + if (is_memcache_enabled()) + { + $select_query = " + SELECT * + from {$CONFIG->dbprefix}metastrings where + ( + (id not in (select name_id from {$CONFIG->dbprefix}metadata)) AND + (id not in (select value_id from {$CONFIG->dbprefix}metadata)) AND + (id not in (select name_id from {$CONFIG->dbprefix}annotations)) AND + (id not in (select value_id from {$CONFIG->dbprefix}annotations)) + )"; + + $dead = get_data($select_query); + if ($dead) + { + static $metastrings_memcache; + if (!$metastrings_memcache) + $metastrings_memcache = new ElggMemcache('metastrings_memcache'); + foreach ($dead as $d) + $metastrings_memcache->delete($d->string); + } + } + $query = " DELETE from {$CONFIG->dbprefix}metastrings where -- cgit v1.2.3