[dw-free] Create local secret cache
[commit: http://hg.dwscoalition.org/dw-free/rev/43f4ee4c3b3e]
Create local secret cache
These things are created once an hour and never change for a given time.
Instead of hitting memcache every single time, let's create a local cache.
Patch by
mark.
Files modified:
Create local secret cache
These things are created once an hour and never change for a given time.
Instead of hitting memcache every single time, let's create a local cache.
Patch by
Files modified:
- cgi-bin/ljlib.pl
--------------------------------------------------------------------------------
diff -r c232f9606422 -r 43f4ee4c3b3e cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl Thu Feb 09 23:09:34 2012 +0000
+++ b/cgi-bin/ljlib.pl Thu Feb 09 23:10:32 2012 +0000
@@ -193,6 +193,7 @@
%LJ::DB_REPORT_HANDLES = ();
my $GTop; # GTop object (created if $LJ::LOG_GTOP is true)
+my %SecretCache;
## if this library is used in a BML page, we don't want to destroy BML's
## HUP signal handler.
@@ -1475,7 +1476,7 @@
}
my $memkey = "secret:$time";
- my $secret = LJ::MemCache::get($memkey);
+ my $secret = ($SecretCache{$memkey} ||= LJ::MemCache::get($memkey));
return $want_new ? ($time, $secret) : $secret if $secret;
my $dbh = LJ::get_db_writer();
@@ -1483,7 +1484,8 @@
$secret = $dbh->selectrow_array("SELECT secret FROM secrets ".
"WHERE stime=?", undef, $time);
if ($secret) {
- LJ::MemCache::set($memkey, $secret) if $secret;
+ $SecretCache{$memkey} = $secret;
+ LJ::MemCache::set($memkey, $secret);
return $want_new ? ($time, $secret) : $secret;
}
--------------------------------------------------------------------------------
