Skip to content

Commit

Permalink
disable caching by default, to ease installation
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Sep 20, 2011
1 parent be65eff commit 3eb1d56
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
10 changes: 4 additions & 6 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ The documentation can be found at http://moritz.faui2k3.org/en/ilbot

Installation instructs are still sorely missing, sorry about that.

Note that pages are cached for performance reason; after you change
anything significant, remove the file cache:

rm -rf /tmp/FileCache/irclog/

Before reloading the page in your browser.
Note that in production mode, pages are cached for performance reason.
During the installation, you should have caching disabled (by
setting NO_CACHE = 1 in cgi.conf). Once you're confident with your setup,
remove that setting again.
1 change: 1 addition & 0 deletions cgi/cgi.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
BASE_URL = /
NO_CACHE = 1
25 changes: 15 additions & 10 deletions cgi/channel-index.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,30 @@
use lib 'lib';
use IrcLog qw(get_dbh gmt_today);

my $conf = Config::File::read_config_file('cgi.conf');

# test_calendar();
go();

sub go {
my $q = new CGI;
my $q = CGI->new;
my $channel = $q->url_param('channel');
print "Content-Type: text/html; charset=utf-8\n\n";

my $cache_name = $channel . '|' . gmt_today();
my $cache = new Cache::FileCache({ namespace => 'irclog' });
my $data = $cache->get($cache_name);
if ($conf->{NO_CACHE}) {
print get_channel_index($channel);
} else {
my $cache_name = $channel . '|' . gmt_today();
my $cache = new Cache::FileCache({ namespace => 'irclog' });
my $data = $cache->get($cache_name);

if (! defined $data) {
$data = get_channel_index($channel);
$cache->set($data, '2 hours');
}
if (! defined $data) {
$data = get_channel_index($channel);
$cache->set($data, '2 hours');
}

print $data;
print $data;
}
}

sub test_calendar {
Expand All @@ -41,7 +47,6 @@ sub test_calendar {

sub get_channel_index {
my $channel = shift;
my $conf = Config::File::read_config_file('cgi.conf');
my $base_url = $conf->{BASE_URL} || q{/};

my $t = HTML::Template->new(
Expand Down
26 changes: 15 additions & 11 deletions cgi/index.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@
use Cache::FileCache;

print http_header();
my $cache = new Cache::FileCache( {
namespace => 'irclog',
} );

my $data;
$data = $cache->get('index');
if ( ! defined $data){
$data = get_index();
$cache->set('index', $data, '5 hours');
my $conf = Config::File::read_config_file('cgi.conf');

if ($conf->{NO_CACHE}) {
print get_index();
} else {
my $cache = new Cache::FileCache( {
namespace => 'irclog',
} );

my $data = $cache->get('index');
if ( ! defined $data){
$data = get_index();
$cache->set('index', $data, '5 hours');
}
print $data;
}
print $data;

sub get_index {

my $dbh = get_dbh();

my $conf = Config::File::read_config_file('cgi.conf');
my $base_url = $conf->{BASE_URL} || q{/irclog/};

my $sth = $dbh->prepare("SELECT DISTINCT channel FROM irclog");
Expand Down
4 changes: 3 additions & 1 deletion cgi/out.pl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
}


{
if ($conf->{NO_CACHE}) {
print irclog_output($date, $channel);
} else {
my $cache_key = $channel . '|' . $date . '|' . $count;
# the current date is different from all other pages,
# because it doesn't have a 'next day' link, so make
Expand Down

0 comments on commit 3eb1d56

Please sign in to comment.