mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
tag add more customized options + NexusDB::rememter()
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Nexus\Database;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class NexusDB
|
||||
@@ -267,6 +268,24 @@ class NexusDB
|
||||
return DB::transaction($callback, $attempts);
|
||||
}
|
||||
|
||||
public static function remember($key, $ttl, \Closure $callback)
|
||||
{
|
||||
if (IN_NEXUS) {
|
||||
global $Cache;
|
||||
$result = $Cache->get_value($key);
|
||||
if ($result === false) {
|
||||
do_log("cache miss, get from database.");
|
||||
$result = $callback();
|
||||
$Cache->cache_value($key, $result, $ttl);
|
||||
} else {
|
||||
do_log("cache hit.");
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
return Cache::remember($key, $ttl, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getMysqlColumnInfo($table, $column)
|
||||
{
|
||||
static $driver;
|
||||
|
||||
Reference in New Issue
Block a user