<?php
 namespace Module\ShortLink\Util; use Illuminate\Support\Facades\Cache; use ModStart\Core\Dao\ModelUtil; class LinkDomainUtil { const CACHE_KEY_PREFIX = 'LinkDomain.'; public static function clearCache() { Cache::forget(self::CACHE_KEY_PREFIX . 'List'); } public static function listAllWithCache($minutes = 60) { return Cache::remember(self::CACHE_KEY_PREFIX . 'List', $minutes, function () { return self::listAll(); }); } public static function listAll() { $list = ModelUtil::all('link_domain'); foreach ($list as $k => $v) { $list[$k]['_domain'] = preg_replace('/^https?:\\/\\//', '', $v['urlBase']); unset($list[$k]['id'], $list[$k]['created_at'], $list[$k]['updated_at']); } return $list; } public static function getByUrlBase($urlBase) { foreach (self::listAllWithCache() as $one) { if ($one['urlBase'] == $urlBase) { return $one; } } return null; } }