说明

可支持设置各种数据类型的缓存,当expire参数未指定将默认使用初始化时的全局expire参数。详见:[初始化]

语法

  1. Cache::set(string $key,Any $value,integer $expire = 0);

示例代码

  1. <?php
  2. require 'vendor/autoload.php';
  3. use renpengpeng\Cache;
  4. Cache::connect([
  5. 'type' => 'File',
  6. 'file' => [
  7. 'cache_dir' => realpath(__DIR__).DIRECTORY_SEPARATOR.'cache'
  8. ]
  9. ],true);
  10. // Integer 类型
  11. Cache::set('integer',1);
  12. // Float 类型
  13. Cache::set('float',0.14156);
  14. // String 类型
  15. Cache::set('string','string');
  16. // Object 类型
  17. Cache::set('object',new stdClass());
  18. // Array 类型
  19. Cache::set('array',[1,2,3,4,5]);
  20. // 指定缓存时间:10秒
  21. Cache::set('cache_expire','缓存内容',10);

参数说明

参数 类型 说明
key string 缓存键
value any 缓存值
expire integer 缓存时间,0为永久