mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-26 22:02:13 +09:00
Merge pull request #344 from kijin/pr/widget-cache
#270 위젯 캐싱에 다양한 시간 단위를 사용할 수 있도록 함
This commit is contained in:
commit
77c0fcd139
4 changed files with 71 additions and 17 deletions
|
|
@ -179,8 +179,8 @@ $lang->private = 'private';
|
|||
$lang->etc = 'Others';
|
||||
$lang->unit_sec = 'sec';
|
||||
$lang->unit_min = 'min';
|
||||
$lang->unit_hour = 'hr';
|
||||
$lang->unit_day = 'th';
|
||||
$lang->unit_hour = 'hour';
|
||||
$lang->unit_day = 'day';
|
||||
$lang->unit_month = 'month';
|
||||
$lang->unit_year = 'year';
|
||||
$lang->unit_count = 'count';
|
||||
|
|
|
|||
|
|
@ -119,6 +119,20 @@ function doFillWidgetVars() {
|
|||
if(node.type == 'button') continue;
|
||||
if(node.name === '') continue;
|
||||
|
||||
if (node.name == 'widget_cache') {
|
||||
var widget_cache = selected_node.getAttribute(node.name);
|
||||
var widget_cache_unit = widget_cache.match(/[smhd]$/i);
|
||||
if (widget_cache_unit) {
|
||||
jQuery("#widget_cache_unit").val(widget_cache_unit);
|
||||
widget_cache = widget_cache.replace(/[smhd]$/i, "");
|
||||
}
|
||||
jQuery("#widget_cache").val(widget_cache);
|
||||
continue;
|
||||
}
|
||||
if (node.name == 'widget_cache_unit') {
|
||||
continue;
|
||||
}
|
||||
|
||||
var length = node.length;
|
||||
var type = node.type;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,14 @@
|
|||
<div class="x_control-group">
|
||||
<label class="x_control-label" for="widget_cache">{$lang->widget_cache}</label>
|
||||
<div class="x_controls">
|
||||
<input type="number" name="widget_cache" id="widget_cache" value="0" size="2" /> {$lang->unit_min}
|
||||
<input type="number" name="widget_cache" id="widget_cache" value="0" size="5" />
|
||||
<select name="widget_cache_unit" id="widget_cache_unit" style="width:60px;min-width:60px">
|
||||
<option value="s">{$lang->unit_sec}</option>
|
||||
<option value="m" selected="selected">{$lang->unit_min}</option>
|
||||
<option value="h">{$lang->unit_hour}</option>
|
||||
<option value="d">{$lang->unit_day}</option>
|
||||
</select>
|
||||
<br />
|
||||
<p class="x_help-inline">{$lang->about_widget_cache}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -333,7 +333,11 @@ class widgetController extends widget
|
|||
$widget = $args->widget;
|
||||
$sequence = $args->widget_sequence;
|
||||
$cache = $args->widget_cache;
|
||||
if(!$sequence || !$cache) continue;
|
||||
if(!$cache) continue;
|
||||
if(!$sequence)
|
||||
{
|
||||
$sequence = sha1(json_encode($args));
|
||||
}
|
||||
|
||||
if(count($args))
|
||||
{
|
||||
|
|
@ -342,9 +346,9 @@ class widgetController extends widget
|
|||
// If the cache file for each language widget regeneration
|
||||
foreach($lang_list as $lang_type => $val)
|
||||
{
|
||||
$cache_file = sprintf('%s%d.%s.cache', $this->cache_path, $sequence, $lang_type);
|
||||
$cache_file = sprintf('%s%s.%s.cache', $this->cache_path, $sequence, $lang_type);
|
||||
if(!file_exists($cache_file)) continue;
|
||||
$this->getCache($widget, $args, $lang_type, true);
|
||||
$this->getCache($widget, $args, $lang_type, true, $sequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -352,18 +356,38 @@ class widgetController extends widget
|
|||
/**
|
||||
* @brief Widget cache handling
|
||||
*/
|
||||
function getCache($widget, $args, $lang_type = null, $ignore_cache = false)
|
||||
function getCache($widget, $args, $lang_type = null, $ignore_cache = false, $override_sequence = false)
|
||||
{
|
||||
// If the specified language specifies the current language
|
||||
if(!$lang_type) $lang_type = Context::getLangType();
|
||||
// widget, the cache number and cache values are set
|
||||
$widget_sequence = $args->widget_sequence;
|
||||
// Use the current language if not otherwise specified
|
||||
if (!$lang_type)
|
||||
{
|
||||
$lang_type = Context::getLangType();
|
||||
}
|
||||
|
||||
// Fix the widget sequence if it is missing
|
||||
$widget_sequence = $override_sequence ?: $args->widget_sequence;
|
||||
if (!$widget_sequence)
|
||||
{
|
||||
$widget_sequence = sha1(json_encode($args));
|
||||
}
|
||||
debugPrint($widget_sequence);
|
||||
|
||||
// Set the widget cache duration
|
||||
$widget_cache = $args->widget_cache;
|
||||
if (preg_match('/^([0-9\.]+)([smhd])$/i', $widget_cache, $matches))
|
||||
{
|
||||
$multipliers = array('s' => 1, 'm' => 60, 'h' => 3600, 'd' => 86400);
|
||||
$widget_cache = intval(floatval($matches[1]) * $multipliers[strtolower($matches[2])]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$widget_cache = intval(floatval($widget_cache) * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Even if the cache number and value of the cache and return it to extract data
|
||||
*/
|
||||
if(!$ignore_cache && (!$widget_cache || !$widget_sequence))
|
||||
if(!$ignore_cache && !$widget_cache)
|
||||
{
|
||||
$oWidget = $this->getWidgetObject($widget);
|
||||
if(!$oWidget || !method_exists($oWidget, 'proc')) return;
|
||||
|
|
@ -394,13 +418,13 @@ class widgetController extends widget
|
|||
*/
|
||||
FileHandler::makeDir($this->cache_path);
|
||||
// Wanted cache file
|
||||
$cache_file = sprintf('%s%d.%s.cache', $this->cache_path, $widget_sequence, $lang_type);
|
||||
$cache_file = sprintf('%s%s.%s.cache', $this->cache_path, $widget_sequence, $lang_type);
|
||||
// If the file exists in the cache, the file validation
|
||||
if(!$ignore_cache && file_exists($cache_file))
|
||||
{
|
||||
$filemtime = filemtime($cache_file);
|
||||
// Should be modified compared to the time of the cache or in the future if creating more than widget.controller.php file a return value of the cache
|
||||
if($filemtime + $widget_cache * 60 > $_SERVER['REQUEST_TIME'] && $filemtime > filemtime(_XE_PATH_.'modules/widget/widget.controller.php'))
|
||||
if($filemtime + $widget_cache > $_SERVER['REQUEST_TIME'] && $filemtime > filemtime(_XE_PATH_.'modules/widget/widget.controller.php'))
|
||||
{
|
||||
$cache_body = FileHandler::readFile($cache_file);
|
||||
$cache_body = preg_replace('@<\!--#Meta:@', '<!--Meta:', $cache_body);
|
||||
|
|
@ -411,7 +435,7 @@ class widgetController extends widget
|
|||
// cache update and cache renewal of the file mtime
|
||||
if(!$oCacheHandler->isSupport())
|
||||
{
|
||||
touch($cache_file);
|
||||
touch($cache_file);
|
||||
}
|
||||
|
||||
$oWidget = $this->getWidgetObject($widget);
|
||||
|
|
@ -422,7 +446,7 @@ class widgetController extends widget
|
|||
$oModuleController->replaceDefinedLangCode($widget_content);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->put($key, $widget_content, $widget_cache * 60);
|
||||
$oCacheHandler->put($key, $widget_content, $widget_cache);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -751,6 +775,10 @@ class widgetController extends widget
|
|||
$vars->colorset = trim($request_vars->colorset);
|
||||
$vars->widget_sequence = (int)($request_vars->widget_sequence);
|
||||
$vars->widget_cache = (int)($request_vars->widget_cache);
|
||||
if($request_vars->widget_cache_unit && in_array($request_vars->widget_cache_unit, array('s', 'm', 'h', 'd')))
|
||||
{
|
||||
$vars->widget_cache .= $request_vars->widget_cache_unit;
|
||||
}
|
||||
$vars->style = trim($request_vars->style);
|
||||
$vars->widget_padding_left = trim($request_vars->widget_padding_left);
|
||||
$vars->widget_padding_right = trim($request_vars->widget_padding_right);
|
||||
|
|
@ -783,7 +811,12 @@ class widgetController extends widget
|
|||
|
||||
if($vars->widget_sequence)
|
||||
{
|
||||
$cache_file = sprintf('%s%d.%s.cache', $this->cache_path, $vars->widget_sequence, Context::getLangType());
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_body = $oCacheHandler->delete('widget_cache:' . $vars->widget_sequence);
|
||||
}
|
||||
$cache_file = sprintf('%s%s.%s.cache', $this->cache_path, $vars->widget_sequence, Context::getLangType());
|
||||
FileHandler::removeFile($cache_file);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue