Bug 18232

Summary: Koha::Cache::flush - Simply flush all caches
Product: Koha Reporter: Olli-Antti Kivilahti <olli-antti.kivilahti>
Component: Architecture, internals, and plumbingAssignee: Olli-Antti Kivilahti <olli-antti.kivilahti>
Status: BLOCKED --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: dcook, J.P.Knight, magnus
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:
Bug Depends on: 16140    
Bug Blocks: 19523    
Attachments: Bug 18232 - Koha::Cache::flush - Simply flush all caches
Bug 18232 - Koha::Cache::flush - Simply flush all caches - Squashable1, fix pesky syspref cache issue

Description Olli-Antti Kivilahti 2017-03-08 15:48:18 UTC
This is handy when upgrading Koha or fiddling with config.
Comment 1 Olli-Antti Kivilahti 2017-03-08 15:50:19 UTC
Created attachment 60922 [details] [review]
Bug 18232 - Koha::Cache::flush - Simply flush all caches

So we can easily and without reading the code, figure out how to flush all caches.

    perl -e 'use Koha::Caches; Koha::Caches::flush();'

This is handy dandy when upgrading Koha or fiddling with configs.
Comment 2 Olli-Antti Kivilahti 2017-03-08 15:52:22 UTC
This might work or might not :)
flush is needed however.
I'll keep posting followups if this doesn't.
Comment 3 Katrin Fischer 2017-10-15 11:56:03 UTC
Assigning to Olli-Antti as he provided the patch.

Patch still applies, but I am not sure how to verify if it works correctly. Running the command from koha-shell gives no feedback, but no error either.
Leaving for another tester.

Something similar might already exist wrapped in commands like 'restart_all' on kohadevbox?
Comment 4 Olli-Antti Kivilahti 2017-10-24 13:50:23 UTC
Created attachment 68468 [details] [review]
Bug 18232 - Koha::Cache::flush - Simply flush all caches - Squashable1, fix pesky syspref cache issue

After flushing Koha::Caches this flush() also removed the references to the singleton caches, forcing
reinstating the cache connection.

C4::Context had a hard-coded package variable referencing to the sysprefs cache.
After flushing for the first time, the reference to the syspref cache was severed for Koha::Caches,
but not to the C4::Context syspref cache,
and flushing started to fail because the syspref cache was no longer referenced from Koha::Caches.

The original change was made to try to get around the memcached cache expiration issues.
And had this unintended side-effect.
Comment 5 Jon Knight 2017-10-25 07:51:17 UTC
Applied to master on my test kohadevbox cleanly and:

perl -e 'use Koha::Caches; Koha::Caches::flush();'

seems to run without any errors.

As with Katrin, I could do with a test plan to check its working.  I've tried poking around in memcached (using `memcached -vv` and `telnet localhost 11211` and then issuing stats commands), but I can't see much difference on a dev box to be honest. I'm guessing it needs a load of traffic sent to it to make the memcached caches fill up so that a flush is noticeable?
Comment 6 David Cook 2019-09-19 01:49:38 UTC
(In reply to Jon Knight from comment #5)
> Applied to master on my test kohadevbox cleanly and:
> 
> perl -e 'use Koha::Caches; Koha::Caches::flush();'
> 
> seems to run without any errors.
> 
> As with Katrin, I could do with a test plan to check its working.  I've
> tried poking around in memcached (using `memcached -vv` and `telnet
> localhost 11211` and then issuing stats commands), but I can't see much
> difference on a dev box to be honest. I'm guessing it needs a load of
> traffic sent to it to make the memcached caches fill up so that a flush is
> noticeable?

You could try the following for a more detailed view of what's in the cache if you have the right tools installed:

memdump --server localhost:11211
(might be memcdump on Debian)

memcat --server localhost:11211 KOHADEV:syspref:syspref_opacnavright
(might be memccat)
Comment 7 Magnus Enger 2022-11-14 09:32:10 UTC
Do we still need this after Bug 20116, which added misc/bin/clear_cache.pl?