依赖注入Laravel缓存系统


Dependency Injecting the Laravel Cache System

是否有办法注入底层缓存系统并访问增量方法?

'Cache::increment('key');

到目前为止,我有以下,但没有增加方法。

/**
 * @var Cache'Repository
 */
protected $cache;
/**
 * RateLimiter constructor.
 *
 * @param Cache'Repository $cache
 */
public function __construct(Cache'Repository $cache)
{
    $this->cache = $cache;
}

我已经尝试注入Cache'Store,但这是不可实例化的

编辑:

use Illuminate'Contracts'Cache;在上面的提取物中没有显示,但它是存在的。

有什么建议吗? ?

根据官方文件Cache立面的下划线类别是Illuminate'Cache'Repository,而不是Cache'Repository