webman 怎么使用laravel cache?

0

移植了/congfig/cache.php ;
use Illuminate\Support\Facades\Cache ;


测试后提示:
RuntimeException: A facade root has not been set. in F:\webman\vendor\illuminate\support\Facades\Facade.php:258
Stack trace:
F:\webman\app\controller\Index.php(10): Illuminate\Support\Facades\Facade::__callStatic('add', Array)
F:\webman\vendor\workerman\webman-framework\src\App.php(146): app\controller\Index->index(Object(support\Request))
F:\webman\vendor\workerman\workerman\Connection\TcpConnection.php(637): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))
F:\webman\vendor\workerman\workerman\Events\Select.php(293): Workerman\Connection\TcpConnection->baseRead(Resource id #196)
F:\webman\vendor\workerman\workerman\Worker.php(2430): Workerman\Events\Select->loop()
F:\webman\vendor\workerman\workerman\Worker.php(1417): Workerman\Worker->run()
F:\webman\vendor\workerman\workerman\Worker.php(1360): Workerman\Worker::forkWorkersForWindows()
F:\webman\vendor\workerman\workerman\Worker.php(542): Workerman\Worker::forkWorkers()
F:\webman\start.php(156): Workerman\Worker::runAll()
{main}

已邀请:

nitron

赞同来自: wanbao520

主要使用文件缓存的话,就比较简单,我只告诉你简单实现过程,具体实际需求自己修改代码
composer require illuminate/cache
composer require illuminate/filesystem


<?php

namespace support\bootstrap;
use Webman\Bootstrap;
use Illuminate\Cache\FileStore;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Cache\Repository;

class Cache implements Bootstrap
{

protected static $_instance = [];

public static function start($worker) {
$fileStore = new FileStore(new Filesystem(),runtime_path());
self::$_instance = new Repository($fileStore);
}

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

然后 config/bootstrap.php内加入一行


return [
......
support\bootstrap\Cache::class,
]

然后重启就可以了

wanbao520

赞同来自:

主要是想使用文件缓存,这个功能!

nitron

赞同来自:

@yzh52521
还是简单写的,请根据自己的具体业务需求修改,没有跟laravel一样封装多种缓存驱动,


composer require illuminate/cache
composer require predis/predis

<?php

namespace support\bootstrap;

use Webman\Bootstrap;
use Illuminate\Container\Container;
use Illuminate\Redis\RedisManager;
use Illuminate\Cache\CacheManager;

class Cache implements Bootstrap
{

protected static $_instance = [];

public static function start($worker) {
$container = new Container;
$container['config'] = [
'cache.default' => 'redis',
'cache.stores.redis' => [
'driver' => 'redis',
'connection' => 'default'
],
'cache.prefix' => 'webman',
'database.redis' => [
'cluster' => false,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
'password' => null
],
]
];

$container['redis'] = new RedisManager($container, 'predis', $container['config']['database.redis']);
$cache = new CacheManager($container);
static::$_instance = $cache->store();
}

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

要回复问题请先登录注册