-
-use Cache::SharedMemoryCache;
-my %cache_options = ( 'namespace' => 'MemoriesStuff',
- 'default_expires_in' => 600 );
-my $cache =
- new Cache::SharedMemoryCache( \%cache_options ) or
- croak( "Couldn't instantiate SharedMemoryCache" );
-
-sub zap_cache { $cache->Clear }
-use Storable qw(freeze); use MIME::Base64;
-sub do_cached {
- my ($self, $codeblock,$arg) = @_;
- my $key = 0+$codeblock; if ($arg) { $key .=":".encode_base64(freeze(\$arg)); }
- my $c = $cache->get(0+$codeblock); return @$c if $c;
- my @stuff = $codeblock->($arg);
- $cache->set(0+$codeblock, [ @stuff ]);
- return @stuff;
-}
-
-sub _recent_uploads { Memories::Photo->search_recent() }
-sub _random { Memories::Photo->search_random() }
-
-sub recent_uploads { shift->do_cached(\&_recent_uploads) }
-sub random { shift->do_cached(\&_random) }
-sub tagcloud { shift->do_cached(\&_tagcloud) }
-
-sub _tagcloud {
- my $cloud = HTML::TagCloud->new();
- my $base = Memories->config->uri_base."tag/view/";
- for my $tagging (Memories::Tagging->search_summary) {
- my $name = $tagging->tag->name;
- $cloud->add($name,
- $base.uri_escape($name),
- $tagging->{count}
- )
- }
- $cloud
+for my $how (qw(random recent interesting popular)) {
+ no strict;
+ my $method = "search_$how";
+ *{"_$how"} = sub { Memories::Photo->$method };
+ *{$how} = sub { shift->do_cached(\&{"_$how"})};