View | Details | Raw Unified | Return to bug 7248
Collapse All | Expand All

(-)a/Koha/Cache.pm (-6 / +19 lines)
Lines 55-66 __PACKAGE__->mk_ro_accessors( qw( cache ) ); Link Here
55
55
56
sub new {
56
sub new {
57
    my $class = shift;
57
    my $class = shift;
58
    my $param = shift;
58
#    my $param = shift;
59
    my $cache_type = $param->{cache_type} || 'memcached';
59
    my $cache;
60
    my $subclass = __PACKAGE__."::".ucfirst($cache_type);
60
    my $subclass;
61
    my $cache    = $subclass->_cache_handle($param)
61
    # try to find which cache type we use
62
      or croak "Cannot create cache handle for '$cache_type'";
62
    if ($ENV{'MEMCACHED_SERVERS'}) {
63
    return bless $class->SUPER::new({cache => $cache}), $subclass;
63
        # we use MEMCACHE
64
        $subclass = __PACKAGE__."::Memcached";
65
        $cache    = $subclass->_cache_handle(
66
            {'cache_type'    => 'memcached',
67
            'cache_servers' => $ENV{'MEMCACHED_SERVERS'},
68
            'namespace'     => $ENV{'MEMCACHED_NAMESPACE'},
69
            }
70
        )
71
            or croak "Cannot create cache handle for memcache";
72
        return bless $class->SUPER::new({cache => $cache}), $subclass;
73
    } else {
74
        $ENV{DEBUG} && warn "No caching system";
75
        return;
76
    }
64
}
77
}
65
78
66
=head2 EXPORT
79
=head2 EXPORT
(-)a/opac/svc/report (-16 / +9 lines)
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
}
(-)a/svc/report (-17 / +7 lines)
Lines 29-36 use CGI; Link Here
29
my $query  = CGI->new();
29
my $query  = CGI->new();
30
my $report = $query->param('id');
30
my $report = $query->param('id');
31
31
32
my $cache;
32
# load caching. If we have one, then we will try to retrieve the report from the cache for better performances
33
my $usecache = C4::Context->ismemcached;
33
use Koha::Cache;
34
my $cache = Koha::Cache->new();
34
35
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {
37
    {
Lines 42-58 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
42
    }
43
    }
43
);
44
);
44
45
45
if ($usecache) {
46
if ($cache) {
46
    require Koha::Cache;
47
    my $page = $cache->get_from_cache("intranet:report:$report");
47
    Koha::Cache->import();
48
    $cache = Koha::Cache->new(
49
        {
50
            'cache_type'    => 'memcached',
51
            'cache_servers' => $ENV{'MEMCACHED_SERVERS'}
52
        }
53
    );
54
    my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha';
55
    my $page = $cache->get_from_cache("$namespace:intranet:report:$report");
56
    if ($page) {
48
    if ($page) {
57
        print $query->header;
49
        print $query->header;
58
        print $page;
50
        print $page;
Lines 72-79 my $lines = $sth->fetchall_arrayref; Link Here
72
my $json_text = to_json($lines);
64
my $json_text = to_json($lines);
73
print $json_text;
65
print $json_text;
74
66
75
if ($usecache) {
67
if ($cache) {
76
    my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha';
68
    $cache->set_in_cache( "intranet:report:$report",
77
    $cache->set_in_cache( "$namespace:intranet:report:$report",
78
        $json_text, $cache_expiry );
69
        $json_text, $cache_expiry );
79
}
70
}
80
- 

Return to bug 7248