Created attachment 6353 [details] [review] Moved Cache and Memcahed, added syspref and sql entry Some changes from https://github.com/ranginui/koha/commit/2a1f4172dafbfb7435e46762fcfab368d3dceb7a and adding syspref and appropriate database entry.
Created attachment 6354 [details] [review] Git format patch rather than diff
Looks good Chris H, only thing missing is the change to installer/data/mysql/sysprefs.sql
Created attachment 6356 [details] [review] Adds in missing sysprefs.sql entry for usecache setting Cheers for that Chris.
Have signed off, but leaving it in needs signoff as I think we need a signoff from outside Catalyst.
Created attachment 6359 [details] [review] Bug 7248 : Caching support and Syspref In the new Koha namespace as they don't call any routines from C4 Squashed commit of the following: commit c887559d575464f3ac4fccb4db0cce2872cf633c Author: Chris Hall <chrish@catalyst.net.nz> Date: Mon Nov 21 13:33:53 2011 +1300 added missing sysprefs.sql entry for usecache setting http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=7248 commit 177676f5f0591b9231eed73fdb21066589c2274d Author: Chris Hall <chrish@catalyst.net.nz> Date: Mon Nov 21 11:38:23 2011 +1300 Caching support and syspref http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=7248 Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Hi Chris H., can you please add a description and test plan to this bug? As is I have no idea what it's supposed to do and how to test it. Thx! :)
Created attachment 6372 [details] [review] Update to t/Cache.t for better testing of Koha/Cache.pm and Koha/Memcached.pm Hey Katrin Attached is a simple unit test (it requires a Memcached server to be running and configured in your koha-conf.xml). This enhancement moves both Cache.pm and Memcached.pm out of the C4 namespace and into the Koha namespace as well as a minor tidy up (work done by Chris Cormack). This enhancement also adds the appropriate system preferences entries to allow caching to be enabled/disabled globally (from within system prefs -> admin -> caching options -> usecache).
Created attachment 6771 [details] [review] [SIGNED-OFF] Bug 7248 : Caching support and Syspref In the new Koha namespace as they don't call any routines from C4 Squashed commit of the following: commit c887559d575464f3ac4fccb4db0cce2872cf633c Author: Chris Hall <chrish@catalyst.net.nz> Date: Mon Nov 21 13:33:53 2011 +1300 added missing sysprefs.sql entry for usecache setting http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=7248 commit 177676f5f0591b9231eed73fdb21066589c2274d Author: Chris Hall <chrish@catalyst.net.nz> Date: Mon Nov 21 11:38:23 2011 +1300 Caching support and syspref http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=7248 Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz> Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> Adds new system preference usecache under administration. Checked the system preference works. Also ran the test successfully.
Created attachment 6772 [details] [review] [SIGNED-OFF] Unit test for Koha/Cache.pm (which includes Koha/Cache/Memcahed.pm) http://bugs.koha-community.org/show_bug.cgi?id=7248 Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> perl t/Cache.t completes successfully. 1..9 ok 1 - use Koha::Cache; ok 2 - use C4::Context; ok 3 - fetching item NOT in cache ok 4 - fetching expired item from cache ok 5 - fetching valid item from cache ok 6 - fetching cleared item from cache ok 7 - fetching valid item from cache (after clearing another item) ok 8 - fetching flushed item from cache ok 9 - fetching flushed item from cache
QA Comment/Questions: This patch adds a syspref usecache. I would opt for a more specific name. Note that the word usecache is already used in several javascripts. Something like usememcached for instance? If such a pref is added, I would also expect to see it being used. But as I understand, the current test is still if $ENV{'MEMCACHED_SERVERS'} is filled in C4/Context. The value of this pref is never tested? The modules moved to Koha still include references in comments to C4. Could you also eliminate those?
Chris C pointed me to the patches you wrote under 7249 which use the pref. So that question got some clarification. Although that was the most important one, I still think renaming it would be better. Should not be too hard with an intelligent(!) Replace All ;) And the C4 mentions ..
Another comment while browsing through 7249: If we start using your pref, it would be better to eliminate here the old way of testing via $ENV. Make it uniform again. If you do that, we get rid of a "preference" coming via koha-httpd file. Although it would be nice to seek for some concensus on the list, especially with those who worked on this before..
I like the idea of having a system preference to turn it off and on - this will make testing really easy too.
Created attachment 7342 [details] [review] Added caching support and syspref I corrected the documentation in the Koha namespace (corrected C4:: references) and also removed any trace of C4::Cache as it isn't used anymore.
Created attachment 7343 [details] [review] Unit tests for Koha::Cache (incluedes Koha::Cache::Memcached) Corrected patch so it applies cleanly (removing simple conflict as my new patch for adding caching also modified t/Cache.t)
Created attachment 7366 [details] [review] Bug 7248 Added caching support and syspref and moved Caching into Koha namespace Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Created attachment 7367 [details] [review] Bug 7248 Unit test for Koha/Cache.pm (which includes Koha/Cache/Memcahed.pm) Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
I'm uncomfortable with those patches and would like some more explanations * the memcache information are in httpd.conf, right ? So what could be the use of a "usecache" syspref ? just be easier to switch on/off use of caching ? * some things like C4/Languages.pm use memcache as well. Should they rely on this Cache.pm or is it something different ? (not changing the status, I just want to understand)
(In reply to comment #18) > I'm uncomfortable with those patches and would like some more explanations > * the memcache information are in httpd.conf, right ? So what could be the use > of a "usecache" syspref ? just be easier to switch on/off use of caching ? > * some things like C4/Languages.pm use memcache as well. Should they rely on > this Cache.pm or is it something different ? Paul, could you also look at comment 12? We would not like to have multiple ways of doing the same.
+1 for a system preference to turn off/on memcache.
(In reply to comment #19) > Paul, could you also look at comment 12? We would not like to have multiple > ways of doing the same. About comment 12 : If we use syspref to get memcache server informations, it mean we can't cache the syspref (as we need the cache server information to get the cache address) Isn't this a good reason to keep memcache server in httpd.conf ? what is/are the side effect if any of the $ENV ?
(In reply to comment #21) > (In reply to comment #19) > > Paul, could you also look at comment 12? We would not like to have multiple > > ways of doing the same. > > About comment 12 : > If we use syspref to get memcache server informations, it mean we can't cache > the syspref (as we need the cache server information to get the cache address) > Isn't this a good reason to keep memcache server in httpd.conf ? what is/are > the side effect if any of the $ENV ? So there's a special case for the UseCache syspref. The side effect of keeping the memcache configuration in $ENV is that we have to explain to non-technical librarians how to adjust their caching settings if they run into problems. This seems like a significant disadvantage, for no real benefit. Also, regarding the name of the syspref, I think UseCache is better than UseMemcached. One day we may have more than one cache technology available, at which point it could be changed from boolean to a choice, and UseCache = On remapped to UseCache = memcached.
(In reply to comment #22) > > Isn't this a good reason to keep memcache server in httpd.conf ? what is/are > > the side effect if any of the $ENV ? > > So there's a special case for the UseCache syspref. The side effect of keeping > the memcache configuration in $ENV is that we have to explain to non-technical > librarians how to adjust their caching settings if they run into problems. This > seems like a significant disadvantage, for no real benefit. I think that if a librarian run into problems, the thing that must be done is emptying the cache, that must be done on command line. That's not something for anyone. Setting the cache server is also something highly technical, and sysprefs should be dedicated to library/user-oriented things. This setting is the same as for the LDAP = that's in koha.conf, not in syspref. I think we should have as a rule that : * technical parameters are in koha.xml or httpd.conf * librarian parameters are in syspreferences > Also, regarding the name of the syspref, I think UseCache is better than > UseMemcached. One day we may have more than one cache technology available, at > which point it could be changed from boolean to a choice, and UseCache = On > remapped to UseCache = memcached. agreed
I have no objection to the setting being in koha-conf.xml, if you feel there is no way to specify cache settings in system preferences (I'd argue that LDAP should also be specified in system preferences, and that it's oversight that it still requires editing configuration files manually). koha-conf is a place for *Koha* configuration settings. The Apache config is not.
I think we must discuss of where to put those files. I plan to send mails to koha-devel about all "in discussion" bugs, will do that tomorrow
(In reply to comment #24) > I have no objection to the setting being in koha-conf.xml, if you feel there is > no way to specify cache settings in system preferences (I'd argue that LDAP > should also be specified in system preferences, and that it's oversight that it > still requires editing configuration files manually). koha-conf is a place for > *Koha* configuration settings. The Apache config is not. First, I just noticed this bug. I hope it is not late to step in. I agree caching should be handled in a uniform and consistent way. The only reason to put memcached server(s) settings inside the Apache config is to be able to cache de koha-conf.xml file itself. This has been discussed on bug 6193. Otherwise, it can be put anywhere (koha-conf.xml or db). There's also a second patch in bug 6193, that reuses those settings read from ENV, and the C4::Context->memcached object itself (and thus removes lots of calls to sysprefs in several koha libraries too). Regarding the 'special-non-cached' syspref usecache, it could be tested before setting the memcached stuff in C4::Context and thus provide a way to disable caching for the librarians. I sent an email to the list to discuss caching, as we have two different ways of dealing with it right now, and not a proper solution to cache invalidation, which actually annoys several librarians here (think of languages, changes on frameworks, etc). I hope we can discuss it on the list soon.
Following discussion & decision on koha-devel, the current patch won't be applied : we have decided to set caching at apache configuration level, bug 6193 has been applied and provide this feature/level of caching. So the "usecache" syspref is now irrelevent (we use cache BEFORE reading syspref) Using Koha/Cache is probably a good idea though, but the patch must be rewritten completly imo. For now, all caching is made with the following code: eval { if (C4::Context->ismemcached) { require Memoize::Memcached; import Memoize::Memcached qw(memoize_memcached); memoize_memcached('getTranslatedLanguages', memcached => C4::Context->memcached); } ->ismemcached answer 1 if memcache is ON C4::Context->memcached returns the handle of the memcache server Some ideas behing this patch are great and should be reintroduced: * use a central/unique Caching place = will let us change the caching system if we want, it's something we can't do with current system * the cache flushing is something we must add, definetly. So you're more than welcomed to rewrite your patch !
I would really like to see this feature in 3.8. I hope it can be fixed and will be happy to test again.
Created attachment 9348 [details] [review] Bug 7248 Added caching support and and moved Caching into Koha namespace Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Created attachment 9349 [details] [review] Bug 7248 Unit test for Koha/Cache.pm (which includes Koha/Cache/Memcached.pm) Note that in order to test Koha::Cache you must export the environment variable MEMCACHED_SERVERS. For example: $ export MEMCACHED_SERVERS=127.0.0.1:11211 Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Created attachment 9352 [details] [review] [SIGNED-OFF] Bug 7248 Added caching support and and moved Caching into Koha namespace Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Created attachment 9353 [details] [review] [SIGNED-OFF] Bug 7248 Unit test for Koha/Cache.pm (which includes Koha/Cache/Memcached.pm) Note that in order to test Koha::Cache you must export the environment variable MEMCACHED_SERVERS. For example: $ export MEMCACHED_SERVERS=127.0.0.1:11211 Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Created attachment 9360 [details] [review] Bug 7248 Added caching support and and moved Caching into Koha namespace Unit test for Koha/Cache.pm (which includes Koha/Cache/Memcached.pm) Note that in order to test Koha::Cache you must export the environment variable MEMCACHED_SERVERS. For example: $ export MEMCACHED_SERVERS=127.0.0.1:11211 Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
passing QA - passes perlcritic OK, and both tests pass OK i've squashed the two patches into one, applied to 142c62081fc15bbd994e737eef55e29b61a6d730
Looking at how this caching works in bug 7249, I think this part of the code is wrong: +if ($usecache) { + require Koha::Cache; + Koha::Cache->import(); + $cache = Koha::Cache->new( + { + 'cache_type' => 'memcached', + 'cache_servers' => $ENV{'MEMCACHED_SERVERS'} + } + ); + my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha'; + my $page = $cache->get_from_cache("$namespace:intranet:report:$report"); + if ($page) { + print $query->header; + print $page; + exit; + } +} => 'memcached' is hardcoded in the file that use caching, the caching mechanism must be generic. The caching API must be something like: use Koha::Cache; my $cache_server = Koha::Cache->new(); if $cache_server( my $page = $cache->get_from_cache("intranet:report:$report");) so it won't depend on the caching system & caching configuration. I'll provide a patch for that ASAP (maybe today)
Hi Paul, I understand what you mean, but couldn't you still push this? I see some reasons: - adding new reports is currently totally broken in master - I am quite sure we have more references for memcache that need to be cleaned up - Koha does only support memcache right now, so it can be pushed without breaking anything - the change you suggest could be done as a follow-up and perhaps do more clean-up in other places at the same time
Created attachment 9552 [details] [review] Bug 7248/7249 follow-up: more generic cache handling This patch update the cache handling to Koha::Cache. So, whatever the cache mechanism is, Koha caching will work this way: use Koha::Cache; my $cache = Koha::Cache->new(); if ($cache) { $cache->get_from_cache($identifier) } if ($cache) { $cache->set_in_cache( $identifier, $value, $cache_expiry ); } Test plan: * setup a Koha with MEMCACHE activated (MEMCACHED_NAMESPACE is defined in koha-httpd.conf) * setup Koha with DEBUG on (SetEnv DEBUG "1" in koha-httpd.conf) * restart Apache * load a report $KOHA/cgi-bin/koha/svc/report?id=<ID> In the Apache logs you will get: * report: We have and will use a cache at /home/paul/koha.dev/koha-community/opac/svc/report line 40. => confirmation we will use memcache * execute_query(<A QUERY>) => the cache is still empty, we run the SQL load the report again, you'll get: * report: We have and will use a cache at /home/paul/koha.dev/koha-community/opac/svc/report line 40. => confirmation we will use memcache * report: Report <ID> retrieved from cache at /home/paul/koha.dev/koha-community/opac/svc/report line 43. => confirmation we are retrieving the result from the cache Remove the MEMCACHE env variable, restart Apache, reload the page, you'll get: * report: No caching system at /home/paul/koha.dev/koha-community/Koha/Cache.pm line 75. => confirmation you have no caching system active
(wait an hour or 2 before testing this patch, i'm working on t/Cache.t and cleaning other instances of caching)
Created attachment 9553 [details] [review] Bug 7248 follow-up (2) Adapting subs using Cache to new Caching API guided_reports, Languages and Biblio::GetMarcStructure where the only subs that used caching This patch switches to the generic Koha::Cache namespace Test plan : * have DEBUG env set to 1 * reach addbiblio page to test the patch in Biblio.pm, or setup more than 1 language * you should see in the logs that you're reading and writing from cache
Created attachment 9554 [details] [review] Bug 7248/7249 follow-up: more generic cache handling This patch update the cache handling to Koha::Cache. So, whatever the cache mechanism is, Koha caching will work this way: use Koha::Cache; my $cache = Koha::Cache->new(); if ($cache) { $cache->get_from_cache($identifier) } if ($cache) { $cache->set_in_cache( $identifier, $value, $cache_expiry ); } Test plan: * setup a Koha with MEMCACHE activated (MEMCACHED_NAMESPACE is defined in koha-httpd.conf) * setup Koha with DEBUG on (SetEnv DEBUG "1" in koha-httpd.conf) * restart Apache * load a report $KOHA/cgi-bin/koha/svc/report?id=<ID> In the Apache logs you will get: * report: We have and will use a cache at /home/paul/koha.dev/koha-community/opac/svc/report line 40. => confirmation we will use memcache * execute_query(<A QUERY>) => the cache is still empty, we run the SQL load the report again, you'll get: * report: We have and will use a cache at /home/paul/koha.dev/koha-community/opac/svc/report line 40. => confirmation we will use memcache * report: Report <ID> retrieved from cache at /home/paul/koha.dev/koha-community/opac/svc/report line 43. => confirmation we are retrieving the result from the cache Remove the MEMCACHE env variable, restart Apache, reload the page, you'll get: * report: No caching system at /home/paul/koha.dev/koha-community/Koha/Cache.pm line 75. => confirmation you have no caching system active
Created attachment 9555 [details] [review] Bug 7248 follow-up (2) Adapting subs using Cache to new Caching API guided_reports, Languages and Biblio::GetMarcStructure where the only subs that used caching This patch switches to the generic Koha::Cache namespace Test plan : * have DEBUG env set to 1 * reach addbiblio page to test the patch in Biblio.pm, or setup more than 1 language * you should see in the logs that you're reading and writing from cache
Created attachment 9556 [details] [review] Bug 7248 follow-up (3): cache the cache handler Before this patch, a cache handler was opened everytime ->new() was called. With this patch, only the 1st call to ->new() create a handler
If anyone can sign-off my 3 follow-ups... there's only one missing, to remove ismemcache from Context.pm and Auth.pm, will do that once those have been pushed. Then, i'll write a wiki page about caching
Created attachment 9567 [details] [review] Bug 7248 follow-up (alternative) This patch introduces some new features for caching system: * the type of caching is retrieved from ENV variable in httpd configuration if not forced when the ->new() is called. * if $ENV{DEBUG} is ON, you'll have feedback when something is set or read from cache * the Koha::Cache->is_cache_active is now available and will return 1 if there is a caching system available. It's a replacement for C4::Context->ismemcached The 2 reports modules have been updated to use this new API
Created attachment 9568 [details] [review] Bug 7248 follow-up (alternative) This patch introduces some new features for caching system: * the type of caching is retrieved from ENV variable in httpd configuration if not forced when the ->new() is called. * if $ENV{DEBUG} is ON, you'll have feedback when something is set or read from cache * the Koha::Cache->is_cache_active is now available and will return 1 if there is a caching system available. It's a replacement for C4::Context->ismemcached The 2 reports modules have been updated to use this new API
Created attachment 9569 [details] [review] Bug 7248 follow-up (alternative) This patch introduces some new features for caching system: * the type of caching is retrieved from ENV variable in httpd configuration if not forced when the ->new() is called. * if $ENV{DEBUG} is ON, you'll have feedback when something is set or read from cache * the Koha::Cache->is_cache_active is now available and will return 1 if there is a caching system available. It's a replacement for C4::Context->ismemcached * fixes the mistake for debug/compress_threshold and expire_time parameters The 2 reports modules have been updated to use this new API
Created attachment 9571 [details] [review] Bug 7248 follow-up (alternative) This patch introduces some new features for caching system: * the type of caching is retrieved from ENV variable in httpd configuration if not forced when the ->new() is called. * if $ENV{DEBUG} is ON, you'll have feedback when something is set or read from cache * the Koha::Cache->is_cache_active is now available and will return 1 if there is a caching system available. It's a replacement for C4::Context->ismemcached * fixes the mistake for debug/compress_threshold and expire_time parameters The 2 report web service modules have been updated to use this new API Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Followup breaks out requirement of Koha::Cache to a universal use, then makes use of the new subroutine. Also centralizes the cache params into Koha::Cache->new(). Also adds a pre-emptive check for ENV variables indicating caching; if not present, will continue to fall back to other methods. Some additional warns if DEBUG is active. All in all, looks okay, and applies cleanly (provided you apply the baseline patch first). Marking Passed QA.
There have been no further reports of problems so I am marking this bug resolved.