💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# $cache ## $cache 默认缓存实例 如果配置文件设置了缓存相关的配置,则框架会自动实例化一个 Cache 类。 一般不用直接使用这个变量,除非在升级,转换需要多个连接的时候。 一般用 cache\_set(), cache\_get() 函数来操作缓存。 使用时,需要配置好 Cache 服务和 PHP 相关的 Cache 扩展,目前支持:apc|xcache|memcached|redis|mysql 。 如果为单机,建议使用 xcache,速度比较快,相关文档:<http://bbs.xiuno.com/thread-8762.htm> 。 【定义】 文件:xiunophp/xiunophp.php 大约 77 行: ``` <pre class="calibre11">``` $cache = !empty($conf['cache']) ? cache_new($conf['cache']) : NULL; ``` ``` 【用例】 ``` <pre class="calibre11">``` <?php $conf = include './conf.php'; include './xiunophp/xiunophp.php'; $cache->set('key1', 'value1'); $cache->get('key1'); ?> ``` ``` 【conf.php】 ``` <pre class="calibre11">``` <?php return array ( // -------------> xiunophp 依赖的配置 'cache'=> array( 'enable' => TRUE, 'type'=> 'xcache', // apc|xcache|memcached|redis|mysql 'memcached'=> array ( 'host'=>'localhost', 'port'=>'11211', ), 'redis'=> array ( 'host'=>'localhost', 'port'=>'6379', ), ), 'tmp_path' => './', // 可以配置为 linux 下的 /dev/shm ,通过内存缓存临时文件 'log_path' => './' ); ?> ``` ```