Skip to content

Instantly share code, notes, and snippets.

@bdunogier
Created September 5, 2012 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdunogier/3635993 to your computer and use it in GitHub Desktop.
Save bdunogier/3635993 to your computer and use it in GitHub Desktop.
Cached module extension*
<?php /* #?ini charset="utf8"?
[ExtensionSettings]
DesignExtensions[]=ezcachedmodule
*/ ?>
<?php
class eZCachedModule
{
public static function generate( $file, $args )
{
extract( $args );
$tpl = templateInit();
$tpl->setVariable( 'value', $Params['Value'] );
$Result['content'] = $tpl->fetch( "design:cachedmodule/view.tpl" );
$Result['path'] = array( array( 'url' => '/cachedmodule/view/',
'text' => 'Cached module testing' ) );
$retval = array( 'content' => $Result,
'scope' => 'cachedmodule' );
return $retval;
}
public static function retrieve( $file, $mtime, $args )
{
$Result = include( $file );
eZDebug::writeDebug( $Result, "Cached module result" );
return $Result;
}
public static function cacheFilePath( $params )
{
$currentSiteAccess = $GLOBALS['eZCurrentAccess']['name'];
$cacheFile = $params['Value'] . '.php';
$cachePath = eZDir::path( array( eZSys::cacheDirectory(), 'cachedmodule', $currentSiteAccess, $cacheFile ) );
eZDebug::writeDebug( $cachePath, 'cacheFilePath' );
return $cachePath;
}
}
?>
<?php /* #?ini charset="utf8"?
[ModuleSettings]
ExtensionRepositories[]=ezcachedmodule
ModuleList[]=cachedmodule
*/ ?>
<?php
$Module = array( "name" => "Cached module" );
$ViewList = array();
$ViewList["view"] = array(
"script" => "view.php",
"params" => array( 'Value' ) );
?>
<?php
//
//
// SOFTWARE NAME: eZ Online Editor
// COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2.0 of the GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of version 2.0 of the GNU General
// Public License along with this program; if not, write to the Free
// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
require_once( "kernel/common/template.php" );
$Module = $Params["Module"];
$cacheFilePath = eZCachedModule::cacheFilePath( $Params );
$cacheFile = eZClusterFileHandler::instance( $cacheFilePath );
$Result = $cacheFile->processCache( array( 'eZCachedModule', 'retrieve' ),
array( 'eZCachedModule', 'generate' ),
null,
null,
compact( 'Params' ) );
return $Result;
?>
<h1>Cached module result</h1>
Value: {$value}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment