OSDN Git Service

Plugin::CompositeCache: fix config initializer
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Plugin / CompositeCache.pm
index ce0aebf..227dfe1 100644 (file)
@@ -10,24 +10,20 @@ sub register {
     my ($self, $app, $conf) = @_;
 
     # merge global config
-    my $cc_conf = $app->config->{Cache} || {};
-    if ($conf) {
-        $conf = { %$cc_conf, %$conf};
-    }
-    $self->{config} = $conf;
+    my $cc_conf = $app->config->{Cache} ||= {};
 
     # define default cache expiration terms (sec.)
-    $conf->{term_units} ||= {};
-    $conf->{term_units}->{very_short} = 30;
-    $conf->{term_units}->{short}      = 180; # 3 minutes
-    $conf->{term_units}->{middle}     = 600; # 10 minutes
-    $conf->{term_units}->{long}       = 3600; # 60 minutes
-    $conf->{term_units}->{very_long}  = 43200; # 12 * 60 minutes;
+    $cc_conf->{term_units} ||= {};
+    $cc_conf->{term_units}->{very_short} = 30;
+    $cc_conf->{term_units}->{short}      = 180; # 3 minutes
+    $cc_conf->{term_units}->{middle}     = 600; # 10 minutes
+    $cc_conf->{term_units}->{long}       = 3600; # 60 minutes
+    $cc_conf->{term_units}->{very_long}  = 43200; # 12 * 60 minutes;
 
-    $conf->{inmemory_ratio} ||= 0.5;
+    $cc_conf->{inmemory_ratio} ||= 0.5;
 
     # define expiration terms
-    $conf->{expire_terms} ||= {
+    $cc_conf->{expire_terms} ||= {
                                "model:users"       => "short",
                                "model:stories"     => "very_short",
                                "model:journals"    => "very_short",
@@ -43,6 +39,10 @@ sub register {
                                "anonymous_user"    => "middle",
                                "Preprocessor"      => "middle",
                               };
+    if ($conf) {
+        $cc_conf = { %$cc_conf, %$conf};
+    }
+    $self->{config} = $cc_conf;
 
     $self->{app} = $app;
     $self->{kvs} = $app->kvs;