Bug 35811

Summary: Adding a new item type does not clear cache (causing new type to not show properly in OPAC)
Product: Koha Reporter: Michał <schodkowy.omegi-0r>
Component: Staff interfaceAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: trivial    
Priority: P5 - low CC: gmcharlt
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:

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?