Cacher.php 903 Bytes
Newer Older
王源's avatar
王源 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
<?php

namespace Meibuyu\Micro\Tools;

use Psr\SimpleCache\CacheInterface;

/**
 * Class Cache
 * @package Meibuyu\Micro\Tools
 * @method static get($key, $default = null)
 * @method static set($key, $value, $ttl = null)
 * @method static delete($key)
 * @method static clear()
 * @method static getMultiple($keys, $default = null)
 * @method static setMultiple($values, $ttl = null)
 * @method static deleteMultiple($keys)
 * @method static has($key)
 */
class Cacher
{

    /**
     * @var CacheInterface
     */
    protected static $driver;

    /**
     * @return CacheInterface
     */
    public static function driver()
    {
        if (!self::$driver) {
            self::$driver = container(CacheInterface::class);
        }
        return self::$driver;
    }

    public static function __callStatic($name, $arguments)
    {
        return static::driver()->{$name}(...$arguments);
    }

}