Lines 28-52
use CGI;
Link Here
|
28 |
my $query = CGI->new(); |
28 |
my $query = CGI->new(); |
29 |
my $report = $query->param('id'); |
29 |
my $report = $query->param('id'); |
30 |
|
30 |
|
31 |
my $cache; |
31 |
# load caching. If we have one, then we will try to retrieve the report from the cache for better performances |
32 |
my $usecache = C4::Context->ismemcached; |
32 |
use Koha::Cache; |
|
|
33 |
my $cache = Koha::Cache->new(); |
33 |
|
34 |
|
34 |
my ( $sql, $type, $name, $notes, $cache_expiry, $public ) = |
35 |
my ( $sql, $type, $name, $notes, $cache_expiry, $public ) = |
35 |
get_saved_report($report); |
36 |
get_saved_report($report); |
36 |
die "Sorry this report is not public\n" unless $public; |
37 |
die "Sorry this report is not public\n" unless $public; |
37 |
|
38 |
|
38 |
if ($usecache) { |
39 |
if ($cache) { |
39 |
require Koha::Cache; |
40 |
$ENV{DEBUG} && warn "We have and will use a cache"; |
40 |
Koha::Cache->import(); |
41 |
my $page = $cache->get_from_cache("opac:report:$report"); |
41 |
$cache = Koha::Cache->new( |
|
|
42 |
{ |
43 |
'cache_type' => 'memcached', |
44 |
'cache_servers' => $ENV{'MEMCACHED_SERVERS'} |
45 |
} |
46 |
); |
47 |
my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha'; |
48 |
my $page = $cache->get_from_cache("$namespace:opac:report:$report"); |
49 |
if ($page) { |
42 |
if ($page) { |
|
|
43 |
$ENV{DEBUG} && warn "Report $report retrieved from cache"; |
50 |
print $query->header; |
44 |
print $query->header; |
51 |
print $page; |
45 |
print $page; |
52 |
exit; |
46 |
exit; |
Lines 61-68
my $lines = $sth->fetchall_arrayref;
Link Here
|
61 |
my $json_text = to_json($lines); |
55 |
my $json_text = to_json($lines); |
62 |
print $json_text; |
56 |
print $json_text; |
63 |
|
57 |
|
64 |
if ($usecache) { |
58 |
if ($cache) { |
65 |
my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha'; |
59 |
$cache->set_in_cache( "opac:report:$report", |
66 |
$cache->set_in_cache( "$namespace:opac:report:$report", |
|
|
67 |
$json_text, $cache_expiry ); |
60 |
$json_text, $cache_expiry ); |
68 |
} |
61 |
} |