| 1 | =head1 NAME | ||
| 2 | |||
| 3 | MKDoc::Core::FileCache - Cache::FileCache wrapper for MKDoc::Core | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | sub cached_foo | ||
| 8 | { | ||
| 9 | my $key = shift; | ||
| 10 | my $foo_cache = MKDoc::Core::FileCache->instance ('foo_cache'); | ||
| 11 | return $foo_cache->get ($key) || do { | ||
| 12 | my $val = compute_expensive_foo ($key); | ||
| 13 | $foo_cache->set ($key, $val, "1 day"); | ||
| 14 | $val; | ||
| 15 | }; | ||
| 16 | } | ||
| 17 | |||
| 18 | =cut | ||
| 19 | package MKDoc::Core::FileCache; | ||
| 20 | use MKDoc::Core; | ||
| 21 | use Cache::FileCache; | ||
| 22 | use strict; | ||
| 23 | use warnings; | ||
| 24 | |||
| 25 | |||
| 26 | sub instance | ||
| 27 | { | ||
| 28 | my $class = shift || return; | ||
| 29 | my $cache = shift || return; | ||
| 30 | my $dir = MKDoc::Core::site_dir(); | ||
| 31 | |||
| 32 | -d "$dir/cache" or mkdir "$dir/cache" or die "No $dir/cache"; | ||
| 33 | return new Cache::FileCache ( { | ||
| 34 | cache_root => "$dir/cache", | ||
| 35 | namespace => $cache, | ||
| 36 | } ); | ||
| 37 | } | ||
| 38 | |||
| 39 | |||
| 40 | 1; |