Kwiki::CachedDisplay - Speed-up Kwiki page display by caching


Kwiki-CachedDisplay documentation Contained in the Kwiki-CachedDisplay distribution.

Index


Code Index:

NAME

Top

  Kwiki::CachedDisplay - Speed-up Kwiki page display by caching

SYNOPSIS

Top

  kwiki -add Kwiki::CachedDisplay

DESCRIPTION

Top

This module use pre-generated page upon rendering, so that each successive page-rendering takes no time in parsing and template-processing. After you install this plugin, new pages will automatically have pre-generated HTML copies on disk. HTML copies for old pages will be generated by next time anyone visit them.

If somehow you want to remove the generated HTML pages, they are under plugin/cached_display directory.

If there are some pages that you never want it to be cached, edit your config.yaml and add a new list called cached_display_ignore. For example:

    cached_display_ignore:
    - SandBox
    - HomePage

That would simply not cache SandBox and HomePage.

If you want to flush the cache if on the condition that one specific page in the setup has changed, you can define the names of these special pages in

    cached_display_dependencies:
    - KwikiNavBar

This would mean that the cache would be invalidated whenever the KwikiNavBar page is changed.

METHODS

Top

register

Kwiki Plugin registration routine.

check_cached

A pre hook routine of the display method in your display class (In most cases, it is Kwiki::Display::display.) It checked whether the cache of the requested page are out-of-dated or not, and regenerate it on necessary.

COPYRIGHT

Top


Kwiki-CachedDisplay documentation Contained in the Kwiki-CachedDisplay distribution.

package Kwiki::CachedDisplay;
use Kwiki::Plugin -Base;
our $VERSION = '0.07';

const class_id => 'cached_display';

sub register {
    my $reg = shift;
    $reg->add(hook => 'display:display', pre  => 'check_cached');
}

sub check_cached {
    my $hook = pop;
    my $display = $self;
    $self = $display->hub->cached_display;
    my $page = $self->pages->current;
    return unless $page->exists;
    return if (defined $self->config->can('cached_display_ignore') and
	       grep {$page->id} @{$self->config->cached_display_ignore});
    my $html = io->catfile($self->plugin_directory,$page->id)->utf8;
    my $content;

    my $depup = 0;
    if (defined $self->config->can('cached_display_dependencies')){
	for (@{$self->config->cached_display_dependencies}){
	    my $deppage = $self->pages->new_page($_);
	    $depup = 1 if $deppage->modified_time > $html->mtime;
	}
    }

    if($depup or
       !$html->exists or
       ($page->modified_time > $html->mtime)) {
        my $code = $hook->code;
        $content = $code->($display);
        $html->print($content);
    }
    $content ||= $html->all;
    $hook->cancel;
    return $content;
}

__END__