Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r21628: LJSUP-11728 (expire in-memory caches of ...

Committer: ailyin
LJSUP-11728 (expire in-memory caches of ML variables)
U   trunk/cgi-bin/LJ/Lang.pm
Modified: trunk/cgi-bin/LJ/Lang.pm
===================================================================
--- trunk/cgi-bin/LJ/Lang.pm	2012-04-04 07:04:07 UTC (rev 21627)
+++ trunk/cgi-bin/LJ/Lang.pm	2012-04-04 07:15:35 UTC (rev 21628)
@@ -98,11 +98,20 @@
 my %LN_CODE = ();  # $code -> ^^^^
 my $LAST_ERROR;
 my %TXT_CACHE;
+my $CACHE_CLEAN_TIME = 0;
 
 if ( $LJ::IS_DEV_SERVER || $LJ::IS_LJCOM_BETA ) {
-    our $_hook_is_installed;
-    LJ::register_hook( 'start_request', sub { %TXT_CACHE = (); } )
-        unless $_hook_is_installed++;
+    LJ::register_hook( 'start_request' => sub { %TXT_CACHE = (); } );
+} else {
+    LJ::register_hook( 'start_request' => sub {
+        return unless time > $CACHE_CLEAN_TIME;
+        %TXT_CACHE = ();
+
+        # set up cache expiration in the next 30 to 60 minutes, randomly;
+        # this is relevant in worker processes that run for very long time
+        # without being restarted
+        $CACHE_CLEAN_TIME = time + 1800 + int( rand(1800) );
+    } );
 }
 
 sub last_error {

Tags: ailyin, andy, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments