Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/233876

Change subject: Cache Lua code files in APC
......................................................................

Cache Lua code files in APC

Cache Lua libraries in APC (if available) for up to 5 minutes. Always check the
file's mtime to avoid serving a stale copy.

This code path is hot enough that using APC makes a difference.

Change-Id: I32bad5fd9443c1759fe6dc91f8df2ac2f120d75b
---
M engines/LuaCommon/LuaCommon.php
1 file changed, 21 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto 
refs/changes/76/233876/1

diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php
index a080c0c..7ff498c 100644
--- a/engines/LuaCommon/LuaCommon.php
+++ b/engines/LuaCommon/LuaCommon.php
@@ -303,10 +303,31 @@
         * @return mixed the export list, or null if there isn't one.
         */
        protected function loadLibraryFromFile( $fileName ) {
+               static $cache = null;
+
+               if ( !$cache ) {
+                       $cache = ObjectCache::newAccelerator( array(), 'hash' );
+               }
+
+               $mtime = filemtime( $fileName );
+               if ( $mtime === false ) {
+                       throw new MWException( 'Lua file does not exist: ' . 
$fileName );
+               }
+
+               $cacheKey = wfGlobalCacheKey( __CLASS__, $fileName );
+               $fileData = $cache->get( $cacheKey );
+               if ( $fileData ) {
+                       list( $code, $cachedMtime ) = $fileData;
+                       if ( $cachedMtime >= $mtime ) {
+                               return $content;
+                       }
+               }
                $code = file_get_contents( $fileName );
                if ( $code === false ) {
                        throw new MWException( 'Lua file does not exist: ' . 
$fileName );
                }
+               $cache->set( $cacheKey, array( $code, $mtime ), 60 * 5 );
+
                # Prepending an "@" to the chunk name makes Lua think it is a 
filename
                $module = $this->getInterpreter()->loadString( $code, '@' . 
basename( $fileName ) );
                $ret = $this->getInterpreter()->callFunction( $module );

-- 
To view, visit https://gerrit.wikimedia.org/r/233876
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I32bad5fd9443c1759fe6dc91f8df2ac2f120d75b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to