缓存

1.di.php

// 缓存 - Memcache/Memcached
// $di->cache = new \PhalApi\Cache\MemcacheCache(\PhalApi\DI()->config->get('sys.mc'));;
//redis缓存
// $di->cache = new PhalApi\Cache\RedisCache(\PhalApi\DI()->config->get('sys.redis'));
//文件缓存
$di->cache = new PhalApi\Cache\FileCache(array('path' => API_ROOT . '/runtime', 'prefix' => 'api'));

2.使用

//设置缓存
        \PhalApi\DI()->cache->set('thisYear', 2021, 60);
        //获取缓存
        $data['cache_data']=\PhalApi\DI()->cache->get('thisYear');

 3.配置

  'mc'               => array(
        'host'   => '127.0.0.1',
        'port'   => 11211,
        'weight' => 10
    ),

    /**
     * Redis缓存服务器参考配置
     */
    'redis'            => array(
        'host' => '127.0.0.1',
        'port' => 6379,
        'auth' => 'redis'
    ),

 

posted @ 2021-07-22 15:59  CanyingV  阅读(66)  评论(0编辑  收藏  举报