diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-11-07 12:30:35 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-11-07 12:30:35 +0000 |
commit | b8d457e1523b9f76abcea4ca8c0de8d8f91765f0 (patch) | |
tree | 17f6ac80abfb9d5640e836299c05104ed8f6e0de /engine | |
parent | a062a993431f939779ac1e6c36f7540a5232b7c5 (diff) | |
download | elgg-b8d457e1523b9f76abcea4ca8c0de8d8f91765f0.tar.gz elgg-b8d457e1523b9f76abcea4ca8c0de8d8f91765f0.tar.bz2 |
Refs #529: Experimental caching of metastrings
git-svn-id: https://code.elgg.org/elgg/trunk@2420 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/metastrings.php | 34 |
1 files changed, 34 insertions, 0 deletions
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 |