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

(-)a/C4/Cache.pm (-83 lines)
Lines 1-83 Link Here
1
package C4::Cache;
2
3
# Copyright 2009 Chris Cormack and The Koha Dev Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
C4::Cache - Handling caching of html and Objects for Koha
23
24
=head1 SYNOPSIS
25
26
  use C4::Cache (cache_type => $cache_type, %params );
27
28
=head1 DESCRIPTION
29
30
Base class for C4::Cache::X. Subclasses need to provide the following methods
31
32
B<_cache_handle ($params_hr)> - cache handle creator
33
34
B<set_in_cache ($key, $value, $expiry)>
35
36
B<get_from_cache ($key)>
37
38
B<clear_from_cache ($key)>
39
40
B<flush_all ()>
41
42
=head1 FUNCTIONS
43
44
=cut
45
46
use strict;
47
use warnings;
48
use Carp;
49
50
use base qw(Class::Accessor);
51
52
use C4::Cache::Memcached;
53
54
__PACKAGE__->mk_ro_accessors( qw( cache ) );
55
56
sub new {
57
    my $class = shift;                                                          
58
    my %param = @_;                                                             
59
    
60
    my $cache_type = $param{cache_type} || 'memcached';
61
    my $subclass = __PACKAGE__."::".ucfirst($cache_type);
62
    my $cache    = $subclass->_cache_handle(\%param)
63
      or croak "Cannot create cache handle for '$cache_type'";
64
    return bless $class->SUPER::new({cache => $cache}), $subclass;              
65
}
66
67
=head2 EXPORT
68
69
None by default.
70
71
=head1 SEE ALSO
72
73
C4::Cache::Memcached
74
75
=head1 AUTHOR
76
77
Chris Cormack, E<lt>chris@bigballofwax.co.nzE<gt>
78
79
=cut
80
81
1;
82
83
__END__
(-)a/C4/Cache/Memcached.pm (-76 lines)
Lines 1-76 Link Here
1
package C4::Cache::Memcached;
2
3
# Copyright 2009 Chris Cormack and The Koha Dev Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use Carp;
23
24
use Cache::Memcached;
25
26
use base qw(C4::Cache);
27
28
sub _cache_handle {
29
    my $class  = shift;
30
    my $params = shift;
31
32
    my @servers = split /,/, $params->{'cache_servers'};
33
34
    return Cache::Memcached->new(
35
        servers   => \@servers,
36
        namespace => $params->{'namespace'} || 'KOHA',
37
    );
38
}
39
40
sub set_in_cache {
41
    my ( $self, $key, $value, $expiry ) = @_;
42
    croak "No key" unless $key;
43
44
    if ( defined $expiry ) {
45
        return $self->cache->set( $key, $value, $expiry );
46
    }
47
    else {
48
        return $self->cache->set( $key, $value );
49
    }
50
}
51
52
sub get_from_cache {
53
    my ( $self, $key ) = @_;
54
    croak "No key" unless $key;
55
    return $self->cache->get($key);
56
}
57
58
sub clear_from_cache {
59
    my ( $self, $key ) = @_;
60
    croak "No key" unless $key;
61
    return $self->cache->delete($key);
62
}
63
64
sub flush_all {
65
    my $self = shift;
66
    return $self->cache->flush_all;
67
}
68
69
1;
70
__END__                                                                         
71
                                                                                  
72
=head1 NAME
73
74
C4::Cache::Memcached - memcached subclass of C4::Cache
75
76
=cut
(-)a/Koha/Cache.pm (+82 lines)
Line 0 Link Here
1
package Koha::Cache;
2
3
# Copyright 2009 Chris Cormack and The Koha Dev Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
Koha::Cache - Handling caching of html and Objects for Koha
23
24
=head1 SYNOPSIS
25
26
  use C4::Cache (cache_type => $cache_type, %params );
27
28
=head1 DESCRIPTION
29
30
Base class for C4::Cache::X. Subclasses need to provide the following methods
31
32
B<_cache_handle ($params_hr)> - cache handle creator
33
34
B<set_in_cache ($key, $value, $expiry)>
35
36
B<get_from_cache ($key)>
37
38
B<clear_from_cache ($key)>
39
40
B<flush_all ()>
41
42
=head1 FUNCTIONS
43
44
=cut
45
46
use strict;
47
use warnings;
48
use Carp;
49
50
use base qw(Class::Accessor);
51
52
use Koha::Cache::Memcached;
53
54
__PACKAGE__->mk_ro_accessors( qw( cache ) );
55
56
sub new {
57
    my $class = shift;                                                          
58
    my $param = shift;                                                             
59
    my $cache_type = $param->{cache_type} || 'memcached';
60
    my $subclass = __PACKAGE__."::".ucfirst($cache_type);
61
    my $cache    = $subclass->_cache_handle($param)
62
      or croak "Cannot create cache handle for '$cache_type'";
63
    return bless $class->SUPER::new({cache => $cache}), $subclass;              
64
}
65
66
=head2 EXPORT
67
68
None by default.
69
70
=head1 SEE ALSO
71
72
C4::Cache::Memcached
73
74
=head1 AUTHOR
75
76
Chris Cormack, E<lt>chris@bigballofwax.co.nzE<gt>
77
78
=cut
79
80
1;
81
82
__END__
(-)a/Koha/Cache/Memcached.pm (+75 lines)
Line 0 Link Here
1
package Koha::Cache::Memcached;
2
3
# Copyright 2009 Chris Cormack and The Koha Dev Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use Carp;
23
24
use Cache::Memcached;
25
26
use base qw(Koha::Cache);
27
28
sub _cache_handle {
29
    my $class  = shift;
30
    my $params = shift;
31
    my @servers = split /,/, $params->{'cache_servers'};
32
    return Cache::Memcached->new(
33
        servers   => \@servers,
34
        namespace => $params->{'namespace'} || 'KOHA',
35
    );
36
}
37
38
sub set_in_cache {
39
    my ( $self, $key, $value, $expiry ) = @_;
40
    croak "No key" unless $key;
41
    $self->cache->set_debug;
42
43
    if ( defined $expiry ) {
44
        return $self->cache->set( $key, $value, $expiry );
45
    }
46
    else {
47
        return $self->cache->set( $key, $value );
48
    }
49
}
50
51
sub get_from_cache {
52
    my ( $self, $key ) = @_;
53
    croak "No key" unless $key;
54
    return $self->cache->get($key);
55
}
56
57
sub clear_from_cache {
58
    my ( $self, $key ) = @_;
59
    croak "No key" unless $key;
60
    return $self->cache->delete($key);
61
}
62
63
sub flush_all {
64
    my $self = shift;
65
    return $self->cache->flush_all;
66
}
67
68
1;
69
__END__                                                                         
70
                                                                                  
71
=head1 NAME
72
73
C4::Cache::Memcached - memcached subclass of C4::Cache
74
75
=cut
(-)a/installer/data/mysql/updatedatabase.pl (+6 lines)
Lines 4549-4554 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4549
    print "Upgrade to $DBversion done Koha 3.6.0 release \n";
4549
    print "Upgrade to $DBversion done Koha 3.6.0 release \n";
4550
    SetVersion ($DBversion);
4550
    SetVersion ($DBversion);
4551
}
4551
}
4552
$DBversion = "3.06.00.xxx";
4553
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4554
    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('usecache',0,'If on pages with caching enabled will use caching',NULL,'YesNo')");
4555
    print "Upgradet to $DBversion done (Added syspref usecache, When this preference is turned on pages with with caching support will use caching) \n";
4556
    SetVersion ($DBversion);
4557
}
4552
4558
4553
=head1 FUNCTIONS
4559
=head1 FUNCTIONS
4554
4560
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (-2 / +9 lines)
Lines 94-97 Administration: Link Here
94
            - of CAS when logging out of Koha.
94
            - of CAS when logging out of Koha.
95
        -
95
        -
96
            - The CAS Authentication Server can be found at
96
            - The CAS Authentication Server can be found at
97
            - pref: casServerUrl           
97
            - pref: casServerUrl
98
    Caching options:
99
      -
100
          - pref: usecache
101
            default: 0
102
            choices:
103
              yes: Use
104
              no: "Don't use"
105
          - memcached caching
98
- 

Return to bug 7249