tag add more customized options + NexusDB::rememter()

This commit is contained in:
xiaomlove
2022-03-28 15:58:12 +08:00
parent d15a837188
commit b613a46b8d
13 changed files with 164 additions and 33 deletions

View File

@@ -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;