aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-07 11:47:27 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-07 11:47:27 +0000
commita062a993431f939779ac1e6c36f7540a5232b7c5 (patch)
treeb4179963df09da0b8cdf0e19b21a1617aa8806ff
parentfc110d63a3eb1afdd96d4a832239405b6ff6bcb0 (diff)
downloadelgg-a062a993431f939779ac1e6c36f7540a5232b7c5.tar.gz
elgg-a062a993431f939779ac1e6c36f7540a5232b7c5.tar.bz2
Refs #529: Experimental object level caching
git-svn-id: https://code.elgg.org/elgg/trunk@2419 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/entities.php42
1 files changed, 32 insertions, 10 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 09f5f38f5..1a643762e 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1162,6 +1162,12 @@
if (trigger_elgg_event('update',$entity->type,$entity)) {
$ret = update_data("UPDATE {$CONFIG->dbprefix}entities set owner_guid='$owner_guid', access_id='$access_id', time_updated='$time' WHERE guid=$guid");
+ // If memcache is available then delete this entry from the cache
+ static $newentity_cache;
+ if ((!$newentity_cache) && (is_memcache_available()))
+ $newentity_cache = new ElggMemcache('new_entity_cache');
+ if ($newentity_cache) $new_entity = $newentity_cache->delete($guid);
+
// Handle cases where there was no error BUT no rows were updated!
if ($ret===false)
return false;
@@ -1287,19 +1293,25 @@
{
if (!($row instanceof stdClass))
return $row;
- // See if there are any registered subtype handler classes for this type and subtype
+
+ // Create a memcache cache if we can
+ static $newentity_cache;
+ if ((!$newentity_cache) && (is_memcache_available()))
+ $newentity_cache = new ElggMemcache('new_entity_cache');
+ if ($newentity_cache) $new_entity = $newentity_cache->load($row->guid);
+ if ($new_entity) return $new_entity;
+
+ $new_entity = false;
$classname = get_subtype_class_from_id($row->subtype);
if ($classname!="")
{
if (class_exists($classname))
{
- $tmp = new $classname($row);
+ $new_entity = new $classname($row);
- if (!($tmp instanceof ElggEntity))
+ if (!($new_entity instanceof ElggEntity))
throw new ClassException(sprintf(elgg_echo('ClassException:ClassnameNotClass'), $classname, get_class()));
-
- return $tmp;
}
else
error_log(sprintf(elgg_echo('ClassNotFoundException:MissingClass'), $classname));
@@ -1309,18 +1321,22 @@
switch ($row->type)
{
case 'object' :
- return new ElggObject($row);
+ $new_entity = new ElggObject($row); break;
case 'user' :
- return new ElggUser($row);
+ $new_entity = new ElggUser($row); break;
case 'group' :
- return new ElggGroup($row);
+ $new_entity = new ElggGroup($row); break;
case 'site' :
- return new ElggSite($row);
+ $new_entity = new ElggSite($row); break;
default: throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $row->type));
}
+
}
- return false;
+ // Cache entity if we have a cache available
+ if ($newentity_cache) $newentity_cache->save($new_entity->guid, $new_entity);
+
+ return $new_entity;
}
/**
@@ -1330,6 +1346,12 @@
*/
function get_entity($guid)
{
+ static $newentity_cache;
+ if ((!$newentity_cache) && (is_memcache_available()))
+ $newentity_cache = new ElggMemcache('new_entity_cache');
+ if ($newentity_cache) $new_entity = $newentity_cache->load($guid);
+ if ($new_entity) return $new_entity;
+
return entity_row_to_elggstar(get_entity_as_row($guid));
}