From 2721de5aa6b81e069a44b05e8b8e44c904928301 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Mon, 7 Jul 2014 16:01:17 +0800 Subject: Bug 1033955: backport bug 1028795 to bmo (pre-load all related bugs during show_bug initialisation) --- Bugzilla/Object.pm | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'Bugzilla/Object.pm') diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index e3e4ca229..8a7bba1c5 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -224,6 +224,22 @@ sub initialize { # Provides a mechanism for objects to be cached in the request_cahce +sub object_cache_get { + my ($class, $id) = @_; + return $class->_object_cache_get( + { id => $id, cache => 1}, + $class + ); +} + +sub object_cache_set { + my $self = shift; + return $self->_object_cache_set( + { id => $self->id, cache => 1 }, + $self + ); +} + sub _object_cache_get { my $class = shift; my ($param) = @_; @@ -1456,6 +1472,58 @@ Returns C<1> if the passed-in value is true, C<0> otherwise. =back +=head2 CACHE FUNCTIONS + +=over + +=item C + +=over + +=item B + +Class function which returns an object from the object-cache for the provided +C<$id>. + +=item B + +Takes an integer C<$id> of the object to retrieve. + +=item B + +Returns the object from the cache if found, otherwise returns C. + +=item B + +my $bug_from_cache = Bugzilla::Bug->object_cache_get(35); + +=back + +=item C + +=over + +=item B + +Object function which injects the object into the object-cache, using the +object's C as the key. + +=item B + +(none) + +=item B + +(nothing) + +=item B + +$bug->object_cache_set(); + +=back + +=back + =head1 CLASS FUNCTIONS =over -- cgit v1.2.3-24-g4f1b