From 7d2b1d5c0da0d504aa217d3aa604371dc10a82c7 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 3 Jun 2016 18:12:44 +0000 Subject: [PATCH] Bug 16650 - Add script to clear report caches manually It would be nice if there was an easy way to clear a report cache before it's expiration time. Test Plan: 1) Apply this patch 2) Read the help for misc/cronjobs/clear_report_cache.pl 3) Make a public report 4) Load that public report via svc/report 5) Change the report so it will give different results 6) Reload svc/report, you should get the same results 7) Clear the cache with this script 8) Reload svc/report again, you should now get updated results! --- misc/cronjobs/clear_report_cache.pl | 126 ++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 misc/cronjobs/clear_report_cache.pl diff --git a/misc/cronjobs/clear_report_cache.pl b/misc/cronjobs/clear_report_cache.pl new file mode 100755 index 0000000..a73438f --- /dev/null +++ b/misc/cronjobs/clear_report_cache.pl @@ -0,0 +1,126 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use Getopt::Long; +use Pod::Usage; + +use Koha::Cache; + +my $help; +my $verbose; +my $report_id; +my $report_name; +my @sql_params; +my $type; + +GetOptions( + 'i|id=s' => \$report_id, + 'n|name=s' => \$report_name, + 'p|param=s@' => \@sql_params, + 't|type=s' => \$type, + 'h|help' => \$help, + 'v|verbose' => \$verbose, +); + +pod2usage(1) if ( $help || !( $report_id || $report_name ) ); + +pod2usage(1) if ( $type && ( $type ne 'opac' && $type ne 'intranet' ) ); + +my $cache = Koha::Cache->get_instance(); + +if ( $cache->is_cache_active ) { + my $key = "report:".($report_name ? "name:$report_name" : "id:$report_id") . join( '-', @sql_params ); + + + if ( !$type || $type eq 'opac' ) { + $cache->clear_from_cache("opac:$key"); + say "Cleared cached key 'opac:$key' for opac report " . $report_id || $report_name if $verbose; + } + + if ( !$type || $type eq 'intranet' ) { + $cache->clear_from_cache("intranet:$key"); + say "Cleared cached key 'intranet:$key' for intranet report " . $report_id || $report_name if $verbose; + } + +} else { + say("Cache is not active"); +} +=head1 NAME + +clear_report_cache.pl - Clear the cached version of a public report + +=head1 SYNOPSIS + +clear_report_cache.pl [-i|--id] [-n|--name] [-p|--sql-params] [-t|--type] [-h|--help] [-v|--verbose] + +This script will allow you to clear the cache for a given report even if it has not +yet reached its expiration time. + +Make sure to set your memcached environment variable before running this script + +export MEMCACHED_SERVERS="127.0.0.1:11211" + +export MEMCACHED_NAMESPACE="koha_sitename" + +=head1 OPTIONS + +=over + +=item B<-i|--id> + +The id of the report to be cleared. +Either id or name must be specified. + +=item B<-n|--name> + +The name of the report to be cleared. +Either id or name must be specified. + +=item B<-p|--param> + +Repeatable. Specify a -p parameter for +each sql parameter you pass the report. +The order you specify them here should +match the order you specify when fetching +the report. + +=item B<-t|--type> + +Must be either 'opac' or 'intranet'. + +Specifieds to only clear the cache for +the given report for the opac or intranet. + +If not specified, both will be cleared. + +=item B<-h|--help> + +Print a brief help message + +=item B<-v|--verbose> + +Verbose mode. + +=back + +=head1 AUTHOR + +Kyle M Hall + +=head1 COPYRIGHT + +Copyright 2016 ByWater Solutions + +=head1 LICENSE + +This file is part of Koha. + +Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later version. + +You should have received a copy of the GNU General Public License along +with Koha; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=cut -- 2.1.4