From b6ecbde0a72dcfb6b99a4992d9e18b238e74661c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 10 Mar 2023 15:26:45 +0000 Subject: [PATCH] Bug 30920: (follow-up) Flush on delete We missed the flush on delete triggers for the various caches introduced here. Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit f7164385559002216810656fb51f89a3b2892a2b) Signed-off-by: Matt Blenkinsop --- Koha/AuthorisedValue.pm | 18 ++++++++++++++++-- Koha/ClassSource.pm | 17 +++++++++++++++-- Koha/ItemType.pm | 15 ++++++++++++++- Koha/Library.pm | 15 ++++++++++++++- Koha/Localization.pm | 18 +++++++++++++++++- 5 files changed, 76 insertions(+), 7 deletions(-) diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm index 0fc5f4cd1b..da25d5e058 100644 --- a/Koha/AuthorisedValue.pm +++ b/Koha/AuthorisedValue.pm @@ -24,6 +24,8 @@ use Koha::Database; use base qw(Koha::Object Koha::Object::Limit::Library); +my $cache = Koha::Caches->get_instance(); + =head1 NAME Koha::AuthorisedValue - Koha Authorised value Object class @@ -61,14 +63,26 @@ sub store { $self = $self->SUPER::store; if ($flush) { - my $cache = Koha::Caches->get_instance(); - my $key = "AVDescriptions-".$self->category; + my $key = "AV_descriptions:".$self->category; $cache->clear_from_cache($key); } return $self; } +=head2 delete + +AuthorisedValue specific C to clear relevant caches on delete. + +=cut + +sub delete { + my $self = shift @_; + my $key = "AV_descriptions:".$self->category; + $cache->clear_from_cache($key); + $self->SUPER::delete(@_); +} + =head3 opac_description my $description = $av->opac_description(); diff --git a/Koha/ClassSource.pm b/Koha/ClassSource.pm index cabb0add58..f6994a1763 100644 --- a/Koha/ClassSource.pm +++ b/Koha/ClassSource.pm @@ -22,6 +22,8 @@ use Koha::Database; use base qw(Koha::Object); +my $cache = Koha::Caches->get_instance(); + =head1 NAME Koha::ClassSource - Koha Classfication Source Object class @@ -52,13 +54,24 @@ sub store { $self = $self->SUPER::store; if ($flush) { - my $cache = Koha::Caches->get_instance(); - $cache->clear_from_cache('cn)sources:description'); + $cache->clear_from_cache('cn_sources:description'); } return $self; } +=head2 delete + +ClassSource specific C to clear relevant caches on delete. + +=cut + +sub delete { + my $self = shift @_; + $cache->clear_from_cache('cn_sources:description'); + $self->SUPER::delete(@_); +} + =head3 _type Returns name of corresponding DBIC resultset diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 0a8c335ddf..dbbae3fbfc 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -27,6 +27,8 @@ use Koha::Localizations; use base qw(Koha::Object Koha::Object::Limit::Library); +my $cache = Koha::Caches->get_instance(); + =head1 NAME Koha::ItemType - Koha Item type Object class @@ -59,7 +61,6 @@ sub store { $self = $self->SUPER::store; if ($flush) { - my $cache = Koha::Caches->get_instance(); my $key = "itemtype:description:en"; $cache->clear_from_cache($key); } @@ -67,6 +68,18 @@ sub store { return $self; } +=head2 delete + +ItemType specific C to clear relevant caches on delete. + +=cut + +sub delete { + my $self = shift @_; + $cache->clear_from_cache('itemtype:description:en'); + $self->SUPER::delete(@_); +} + =head3 image_location =cut diff --git a/Koha/Library.pm b/Koha/Library.pm index fa4496c323..2e9259b450 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -29,6 +29,8 @@ use Koha::SMTP::Servers; use base qw(Koha::Object); +my $cache = Koha::Caches->get_instance(); + =head1 NAME Koha::Library - Koha Library Object class @@ -59,13 +61,24 @@ sub store { $self = $self->SUPER::store; if ($flush) { - my $cache = Koha::Caches->get_instance(); $cache->clear_from_cache('libraries:name'); } return $self; } +=head2 delete + +Library specific C to clear relevant caches on delete. + +=cut + +sub delete { + my $self = shift @_; + $cache->clear_from_cache('libraries:name'); + $self->SUPER::delete(@_); +} + =head3 stockrotationstages my $stages = Koha::Library->stockrotationstages; diff --git a/Koha/Localization.pm b/Koha/Localization.pm index 790c8729b4..90201b8870 100644 --- a/Koha/Localization.pm +++ b/Koha/Localization.pm @@ -21,6 +21,8 @@ use Koha::Database; use base qw(Koha::Object); +my $cache = Koha::Caches->get_instance(); + =head1 NAME Koha::Localization - Koha Localization type Object class @@ -42,7 +44,6 @@ sub store { $self = $self->SUPER::store; if ($self->entity eq 'itemtypes') { - my $cache = Koha::Caches->get_instance(); my $key = "itemtype:description:".$self->lang; $cache->clear_from_cache($key); } @@ -50,6 +51,21 @@ sub store { return $self; } +=head2 delete + +Localization specific C to clear relevant caches on delete. + +=cut + +sub delete { + my $self = shift @_; + if ($self->entity eq 'itemtypes') { + my $key = "itemtype:description:".$self->lang; + $cache->clear_from_cache($key); + } + $self->SUPER::delete(@_); +} + sub _type { return 'Localization'; } -- 2.39.5