[Koha-bugs] [Bug 32894] New: Objects cache methods' result without invalidation
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Tue Feb 7 07:26:30 CET 2023
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=32894
Bug ID: 32894
Summary: Objects cache methods' result without invalidation
Change sponsored?: ---
Product: Koha
Version: unspecified
Hardware: All
OS: All
Status: In Discussion
Severity: major
Priority: P5 - low
Component: Architecture, internals, and plumbing
Assignee: koha-bugs at lists.koha-community.org
Reporter: jonathan.druart+koha at gmail.com
QA Contact: testopia at bugs.koha-community.org
CC: m.de.rooy at rijksmuseum.nl,
martin.renvoize at ptfs-europe.com, tomascohen at gmail.com
In some of our Koha:: objects we have methods that cache their result and
return it in subsequent calls. However there is no invalidation of the cache if
the object is modified.
For instance, in Koha/ArticleRequest.pm
sub biblio {
my ($self) = @_;
$self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
return $self->{_biblio};
}
This pattern exists in several places.
It can lead to confusion and incorrect results, such as:
use Koha::ArticleRequests;
my $ar = Koha::ArticleRequest->new({
borrowernumber => 42,
biblionumber => 42,
})->store;
say $ar->biblio->biblionumber; # Display 42, correct
$ar->set({ biblionumber => 24 })->store;
say $ar->biblio->biblionumber; # Display 42, wrong
$ar->discard_changes;
say $ar->biblio->biblionumber; # Display 42, wrong
$ar->delete;
We should remove those caching and rely on DBIC/DBMS caching mechanism instead.
--
You are receiving this mail because:
You are watching all bug changes.
You are the assignee for the bug.
More information about the Koha-bugs
mailing list