Bug 35811 - Adding a new item type does not clear cache (causing new type to not show properly in OPAC)
Summary: Adding a new item type does not clear cache (causing new type to not show pro...
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: Main
Hardware: All All
: P5 - low trivial (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-15 09:34 UTC by Michał
Modified: 2024-01-15 09:34 UTC (History)
1 user (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał 2024-01-15 09:34:18 UTC
Item type descriptions are cached with cache key of 'itemtype:description:'.$lang, which is used by function C4::Biblio::GetAuthorisedValueDesc, used for example in OPAC during display of item's item type in the details view table:

https://github.com/Koha-Community/Koha/blob/3df1cb33c277925b689b1e45c736ea8532bffdff/C4/Biblio.pm#L1434C58-L1434C58

The problem is, when a new item type is added, that cache key isn't flushed, meaning the new item type won't be displayed in OPAC, an empty field will be shown instead. Flushing memcached mitigates this issue.

The cache key is cleared here during tests for instance: https://github.com/Koha-Community/Koha/blob/3df1cb33c277925b689b1e45c736ea8532bffdff/t/db_dependent/Koha/Filter/ExpandCodedFields.t#L71

I suspect the cache flushing should occur in `admin/itemtypes.pl`, after $op 'add_validate'. However, I'm not sure how to get the list of all languages to purge (and I assume all of them should be purged).

I've found code snippet below, but I'm not sure if this approach would be acceptable (after adjusting the regex of course), given this gets cache by `Koha::Cache::Memory::Lite->get_instance` instead of `Koha::Caches->get_instance`...

my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
for my $k ( $memory_cache->all_keys ) {
    $memory_cache->clear_from_cache($k) if $k =~ m{^CircRules:};
}

I've also found this snippet (I see itemtypes.pl calls ->store, so this gets called too):
https://github.com/Koha-Community/Koha/blob/2ce83fc784ad8bc716bd65f14845141097c72b69/Koha/ItemType.pm#L62C1-L63

It seems to purge only English, which might be why I experienced the issue that I've experienced.

So the question that prevails then is: how do we purge all the used languages?