Opened 3 years ago
Closed 3 years ago
#1421 closed Defect (fixed)
Ban/Unban uses doesn't work correctly when memcached is used.
| Reported by: | milan | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | Elgg 1.7 |
| Component: | Core | Version: | 1.6 |
| Severity: | trivial | Keywords: | memcache ban unban |
| Cc: | brettp | Difficulty: |
Description
Basically whenever a user is banned or unbanned by an admin the ElggMemcache 'new_entity_cache' instance isn't deleted for that user guid.
I've updated my engine/lib/users.php for the ban_user function to be:
if (($user) && ($user->canEdit()) && ($user instanceof ElggUser))
{
if (trigger_elgg_event('ban', 'user', $user)) {
// Add reason
if ($reason)
create_metadata($user_guid, 'ban_reason', $reason,'', 0, ACCESS_PUBLIC);
// Set ban flag
$result = update_data("UPDATE {$CONFIG->dbprefix}users_entity set banned='yes' where guid=$user_guid");
// If memcached then we invalidate the cache for this user entity
static $newentity_cache;
if ((!$newentity_cache) && (is_memcache_available()))
$newentity_cache = new ElggMemcache('new_entity_cache');
if ($newentity_cache) $newentity_cache->delete($user_guid);
return $result;
}
}
and i've similarly updated unban_user(). Although it would be nice to have wrapper functions to clear out (i.e. CRUD) these specific instances within a ElggMemcache instance i.e.
// definitely untested example pseudo-code
delete_memcache_value($static, $instance, $key) {
static $$static;
if ((!$$static) && (is_memcache_available()))
$$static = new ElggMemcache($instance);
if ($$static) $$static->delete($key);
}
so you could do:
delete_memcache_value('newentity_cache', 'new_entity_cache', $user_guid);
Although it would be nice is the static variable and instance name of the ElggMemcache shared the same value.
Change History (1)
comment:1 Changed 3 years ago by brettp
- Resolution set to fixed
- Status changed from new to closed
Note: See
TracTickets for help on using
tickets.

(In [svn:3955]) Fixes #1421: Banning and unbanning users invalidates the memcache entity.