<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Vendor\LazyValue; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Input\Response; use Module\Vendor\Cache\CacheUtil; class LazyValueUtil { public static function hash($VKrDJ, $caXDF) { return CacheUtil::rememberForever("LazyValue.{$VKrDJ}", function () use($caXDF) { return md5(serialize($caXDF())); }); } public static function notifyChange($VKrDJ) { CacheUtil::forget("LazyValue.{$VKrDJ}"); } public static function status(&$L58zW) { foreach ($L58zW as $cG5OI) { if (null === $cG5OI) { return 'running'; } } return 'finish'; } public static function generateResponseWithStatus($L58zW) { return Response::generate(0, 'ok', array('status' => LazyValueUtil::status($L58zW), 'value' => $L58zW)); } public static function get($VKrDJ, $f_HcG, $AKKj2, $WoyUP = 86400) { goto rpKEa; g80AW: return @json_decode($VgbTG['value'], true); goto le26l; rpKEa: $b5RtF = array('key' => $VKrDJ, 'param' => json_encode($f_HcG)); goto bNy3y; S_8qW: if ($VgbTG['expire'] < time()) { ModelUtil::update('lazy_value', $b5RtF, array('expire' => time() + $AKKj2, 'lifeExpire' => time() + $WoyUP, 'cacheSeconds' => $AKKj2)); LazyValueJob::createRefresh($VKrDJ, $f_HcG, $AKKj2); } goto g80AW; bNy3y: $VgbTG = ModelUtil::get('lazy_value', $b5RtF); goto x83Jp; x83Jp: if (empty($VgbTG)) { goto aBASW; aBASW: ModelUtil::insert('lazy_value', array('key' => $VKrDJ, 'param' => json_encode($f_HcG), 'expire' => time() + $AKKj2, 'lifeExpire' => time() + $WoyUP, 'cacheSeconds' => $AKKj2, 'value' => null)); goto B6oPi; B6oPi: LazyValueJob::create($VKrDJ, $f_HcG, $AKKj2); goto FMXDB; FMXDB: return null; goto YcjAA; YcjAA: } goto S_8qW; le26l: } public static function watch() { goto sShle; dWCJW: $vc26a = ModelUtil::model('lazy_value')->where('expire', '<', time())->get(array('key', 'param', 'cacheSeconds')); goto hWGtu; sShle: ModelUtil::model('lazy_value')->where('lifeExpire', '<', time())->delete(); goto dWCJW; hWGtu: foreach ($vc26a as $sQwqe) { LazyValueJob::createRefresh($sQwqe->key, @json_decode($sQwqe->param, true), $sQwqe->cacheSeconds); } goto rHlHF; rHlHF: } }