Commit 5c60944b authored by Byron Jones's avatar Byron Jones

Bug 815026: Bugzilla::Object cache should be cleared when an object is updated…

Bug 815026: Bugzilla::Object cache should be cleared when an object is updated or removed from the database r=dkl, a=sgreen
parent 9ae8acb3
...@@ -173,10 +173,20 @@ sub _cache_set { ...@@ -173,10 +173,20 @@ sub _cache_set {
Bugzilla->request_cache->{$cache_key} = $object; Bugzilla->request_cache->{$cache_key} = $object;
} }
sub _cache_remove {
my $class = shift;
my ($param) = @_;
$param->{cache} = 1;
my $cache_key = $class->cache_key($param)
|| return;
delete Bugzilla->request_cache->{$cache_key};
}
sub cache_key { sub cache_key {
my $class = shift; my $class = shift;
my ($param) = @_; my ($param) = @_;
if (ref($param) && $param->{cache} && ($param->{id} || $param->{name})) { if (ref($param) && $param->{cache} && ($param->{id} || $param->{name})) {
$class = blessed($class) if blessed($class);
return $class . ',' . ($param->{id} || $param->{name}); return $class . ',' . ($param->{id} || $param->{name});
} else { } else {
return; return;
...@@ -451,6 +461,8 @@ sub update { ...@@ -451,6 +461,8 @@ sub update {
$self->audit_log(\%changes) if $self->AUDIT_UPDATES; $self->audit_log(\%changes) if $self->AUDIT_UPDATES;
$dbh->bz_commit_transaction(); $dbh->bz_commit_transaction();
$self->_cache_remove({ id => $self->id });
$self->_cache_remove({ name => $self->name }) if $self->name;
if (wantarray) { if (wantarray) {
return (\%changes, $old_self); return (\%changes, $old_self);
...@@ -469,6 +481,8 @@ sub remove_from_db { ...@@ -469,6 +481,8 @@ sub remove_from_db {
$self->audit_log(AUDIT_REMOVE) if $self->AUDIT_REMOVES; $self->audit_log(AUDIT_REMOVE) if $self->AUDIT_REMOVES;
$dbh->do("DELETE FROM $table WHERE $id_field = ?", undef, $self->id); $dbh->do("DELETE FROM $table WHERE $id_field = ?", undef, $self->id);
$dbh->bz_commit_transaction(); $dbh->bz_commit_transaction();
$self->_cache_remove({ id => $self->id });
$self->_cache_remove({ name => $self->name }) if $self->name;
undef $self; undef $self;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment